SlideShare a Scribd company logo
1 of 20
Download to read offline
C             Programming
                       Language
               By:
    Yogendra Pal
yogendra@learnbywatch.com
  Dedicated to My mother and Father
t
                                                               y
         Keep your notebook with you.

Write important point and questions that comes in your mind

     Solve Mind band exercise.


                                                               C
                                       Rewind when not clear


              Ask Questions by call or SMS or by mail


Keep Watching Keep Learning

THIS IS LOOPS


                                   2
Need
• Consider a problem:
  – Write a program that print “Hello” 5 times.
  – One possible statement to solve this problem is :
     • printf(“Hello n Hello n Hello n Hello n Hello);
  – But what if we want to print “Hello” 1000 times?
  – We need a control structure that repeatedly execute
    the following statement.
     • printf(“n Hello);
Decision statements
• To change the control flow of a program we
  use:
  – Branching statements : cause one section of code
    to be executed or not executed, depending on a
    conditional clause.
  – Looping statements : used to repeat a section of
    code a number of times or until some condition
    occurs.
Looping Statements
• Allow the program to repeat a section of code
  any number of times untill some condition
  occures.
Looping statements : 1
• while statement
                     initial_statement;
  – General form:    while(condition){
                           statement;
 while(condition)          iteration_statement;
       statement;    }
• The program will repeatedly execute the
  statement inside the while until the condition
  becomes false (0)
Problems
• Write a program that print “Hello” 5 times.
while(counter <= 5)
  printf(“Hello”);

• This statement reads
   – “while counter is less than or equal to 5 print Hello ”
Multiple Statements
• Put all statements inside the curly { } braces.
               while(condition)
               {
                    statement 1;
                    statement 2;
                    statement 3;
               }
(I ++) or (++ I)
• while (i++ < 10)
  – compare i with 10,
  – increment i.
• while (++i < 10)
  – increment i,
  – compare i with 10.
Problems
• Write a program that print numbers from 1 to 100.
• Write a program that print sum of 10 consecutive
  numbers, enter first number using keyboard.
• Write a program that print all even numbers from
  1 to 100.
• Write a program to find the factorial value of any
  number entered through the keyboard.
break statement
• break statement:
  – Loops can be exited at any point through the use of
    a break statement.
• Write a program that checks whether a given
  number is prime of not.
continue statement
• continue statement:
  – continue starts re-executing the body of the loop
    from the top.
• Write a program that print numbers from 1 to 100
  except the numbers that are divisible by 5 using
  continue statement.
Nested while
while(condition)       while(condition)
      while(condition) {
            statement;       while(condition)
                             {
                                   statement;
while(condition)             }
{                      }
      if(condition)
            statement;
      else
            statement;
}
Mind Bend
     Write a program that print all the numbers
  from 2 to 100 with the indication whether a
  number is prime of not.
Output will be like:
2 : prime
3 : prime
4 : not prime
Looping Statement : 2
• for statement
• General form:
for (initial_statement; condition; iteration_statement)
       body_statement;

           initial_statement;
           while(condition){
                 statement;
                 iteration_statement;
           }
Problems
• Two numbers (x and y) are entered through
  the keyboard. Write a program to find the
  value of xy
• Write a program that print numbers from 1
  to 100 except the numbers that are divisible
  by 5 and 7.
• Write a program to print all characters with
  their ASCII value.

                      16
Looping Statement : 3
• do-while loop
 do{
       statement1;
       statement2
 }while(condition)

• do-while run the statements at least once.
Problems
• Write a program that first take two numbers
  from user and then one operator (+, -, *, /, %)
  and print the result accordingly.
• Now modify the above program that give an
  option to the user to repeat the operation
  again and again with different operator
  choosen by him.
Mind Bend
• Write a program that takes 10 floating-point
  numbers as a input from user and print the
  greatest number.
• Write a program that take floating point
  number from user and print
  – ICE if it is less than 0.
  – WATER if it lies between 0 and 100.
  – STEAM if it is greater then 100.

                           19
To get complete benefit of this tutorial solve all the quiz on
                       www.learnbywatch.com

              For any problem in this tutorial mail me at
                    yogendra@learnbywatch.com
                        with the subject “C”

                     For Other information mail at
                       info@learnbywatch.com


Keep Watching Keep Learning

NEXT IS FUNCTIONS

                                    20

More Related Content

Viewers also liked

Viewers also liked (7)

El aguila de wilmar ivan G L
El aguila de wilmar ivan G LEl aguila de wilmar ivan G L
El aguila de wilmar ivan G L
 
Mmmmmm
MmmmmmMmmmmm
Mmmmmm
 
Olympic slideshow
Olympic slideshowOlympic slideshow
Olympic slideshow
 
Portafolio rocío
Portafolio rocíoPortafolio rocío
Portafolio rocío
 
Lecture 5
Lecture 5Lecture 5
Lecture 5
 
Margareth lota
Margareth lotaMargareth lota
Margareth lota
 
Fundamentals of programming finals.ajang
Fundamentals of programming finals.ajangFundamentals of programming finals.ajang
Fundamentals of programming finals.ajang
 

Similar to Loops

csharp repitition structures
csharp repitition structurescsharp repitition structures
csharp repitition structuresMicheal Ogundero
 
Lab 4 ,5 & 6 Submission (3) 14136_Mohsin Alvi.docx
Lab 4 ,5 & 6 Submission (3) 14136_Mohsin Alvi.docxLab 4 ,5 & 6 Submission (3) 14136_Mohsin Alvi.docx
Lab 4 ,5 & 6 Submission (3) 14136_Mohsin Alvi.docxABDULAHAD507571
 
Basic computer-programming-2
Basic computer-programming-2Basic computer-programming-2
Basic computer-programming-2lemonmichelangelo
 
Md university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab newMd university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab neweyavagal
 
Md university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab newMd university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab newLast7693
 
Md university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab newMd university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab newscottbrownnn
 
1.4 conditions and loops
1.4   conditions and loops1.4   conditions and loops
1.4 conditions and loopsallenbailey
 
Looping in PythonLab8 lecture slides.pptx
Looping in PythonLab8 lecture slides.pptxLooping in PythonLab8 lecture slides.pptx
Looping in PythonLab8 lecture slides.pptxadihartanto7
 
Chapter 9 Conditional and Iterative Statements.pptx
Chapter 9 Conditional and Iterative Statements.pptxChapter 9 Conditional and Iterative Statements.pptx
Chapter 9 Conditional and Iterative Statements.pptxXhelalSpahiu
 
Assembly Language Programming
Assembly Language ProgrammingAssembly Language Programming
Assembly Language ProgrammingNiropam Das
 
Decision Making & Loops
Decision Making & LoopsDecision Making & Loops
Decision Making & LoopsAkhil Kaushik
 
C - Programming Assignment 1 and 2
C - Programming Assignment 1 and 2C - Programming Assignment 1 and 2
C - Programming Assignment 1 and 2Animesh Chaturvedi
 
Acm aleppo cpc training introduction 1
Acm aleppo cpc training introduction 1Acm aleppo cpc training introduction 1
Acm aleppo cpc training introduction 1Ahmad Bashar Eter
 

Similar to Loops (20)

Decision control
Decision controlDecision control
Decision control
 
csharp repitition structures
csharp repitition structurescsharp repitition structures
csharp repitition structures
 
Algorithms - Introduction to computer programming
Algorithms - Introduction to computer programmingAlgorithms - Introduction to computer programming
Algorithms - Introduction to computer programming
 
Lab 4 ,5 & 6 Submission (3) 14136_Mohsin Alvi.docx
Lab 4 ,5 & 6 Submission (3) 14136_Mohsin Alvi.docxLab 4 ,5 & 6 Submission (3) 14136_Mohsin Alvi.docx
Lab 4 ,5 & 6 Submission (3) 14136_Mohsin Alvi.docx
 
Loops
LoopsLoops
Loops
 
Basic computer-programming-2
Basic computer-programming-2Basic computer-programming-2
Basic computer-programming-2
 
Python Basics
Python BasicsPython Basics
Python Basics
 
Md university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab newMd university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab new
 
Md university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab newMd university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab new
 
Md university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab newMd university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab new
 
1.4 conditions and loops
1.4   conditions and loops1.4   conditions and loops
1.4 conditions and loops
 
Looping in PythonLab8 lecture slides.pptx
Looping in PythonLab8 lecture slides.pptxLooping in PythonLab8 lecture slides.pptx
Looping in PythonLab8 lecture slides.pptx
 
Chapter 9 Conditional and Iterative Statements.pptx
Chapter 9 Conditional and Iterative Statements.pptxChapter 9 Conditional and Iterative Statements.pptx
Chapter 9 Conditional and Iterative Statements.pptx
 
Control structures pyhton
Control structures  pyhtonControl structures  pyhton
Control structures pyhton
 
Assembly Language Programming
Assembly Language ProgrammingAssembly Language Programming
Assembly Language Programming
 
Decision Making & Loops
Decision Making & LoopsDecision Making & Loops
Decision Making & Loops
 
C - Programming Assignment 1 and 2
C - Programming Assignment 1 and 2C - Programming Assignment 1 and 2
C - Programming Assignment 1 and 2
 
Programming
ProgrammingProgramming
Programming
 
Acm aleppo cpc training introduction 1
Acm aleppo cpc training introduction 1Acm aleppo cpc training introduction 1
Acm aleppo cpc training introduction 1
 
programming.ppt
programming.pptprogramming.ppt
programming.ppt
 

More from Learn By Watch

Demodulation of fm pll detector
Demodulation of fm pll detectorDemodulation of fm pll detector
Demodulation of fm pll detectorLearn By Watch
 
Demodulation of fm slope and balanced slope detector
Demodulation of fm slope and balanced slope detectorDemodulation of fm slope and balanced slope detector
Demodulation of fm slope and balanced slope detectorLearn By Watch
 
In direct method of fm generation armstrong method
In direct method of fm generation armstrong methodIn direct method of fm generation armstrong method
In direct method of fm generation armstrong methodLearn By Watch
 
Direct method of fm generation hartley oscillator method
Direct method of fm generation hartley oscillator methodDirect method of fm generation hartley oscillator method
Direct method of fm generation hartley oscillator methodLearn By Watch
 
Spectrum and power of wbfm
Spectrum and power of wbfmSpectrum and power of wbfm
Spectrum and power of wbfmLearn By Watch
 
Narrow band frequency modulation nbfm
Narrow band frequency modulation nbfmNarrow band frequency modulation nbfm
Narrow band frequency modulation nbfmLearn By Watch
 
General expression of fm signal
General expression of fm signalGeneral expression of fm signal
General expression of fm signalLearn By Watch
 
Frequency division multiplexing
Frequency division multiplexingFrequency division multiplexing
Frequency division multiplexingLearn By Watch
 
Demodulation of ssb synchronous detector
Demodulation of ssb synchronous detectorDemodulation of ssb synchronous detector
Demodulation of ssb synchronous detectorLearn By Watch
 
Generarion of ssb phase discrimination method
Generarion of ssb phase discrimination methodGenerarion of ssb phase discrimination method
Generarion of ssb phase discrimination methodLearn By Watch
 
Generarion of ssb frequency discrimination method
Generarion of ssb frequency discrimination methodGenerarion of ssb frequency discrimination method
Generarion of ssb frequency discrimination methodLearn By Watch
 
Demodulation of dsb sc costas receiver
Demodulation of dsb sc costas receiverDemodulation of dsb sc costas receiver
Demodulation of dsb sc costas receiverLearn By Watch
 
Quadrature carrier multiplexing qam
Quadrature carrier multiplexing qamQuadrature carrier multiplexing qam
Quadrature carrier multiplexing qamLearn By Watch
 
Demodulation of am synchronous detector
Demodulation of am synchronous detectorDemodulation of am synchronous detector
Demodulation of am synchronous detectorLearn By Watch
 

More from Learn By Watch (20)

Tutorial 9 fm
Tutorial 9 fmTutorial 9 fm
Tutorial 9 fm
 
Phase modulation
Phase modulationPhase modulation
Phase modulation
 
Demodulation of fm pll detector
Demodulation of fm pll detectorDemodulation of fm pll detector
Demodulation of fm pll detector
 
Demodulation of fm slope and balanced slope detector
Demodulation of fm slope and balanced slope detectorDemodulation of fm slope and balanced slope detector
Demodulation of fm slope and balanced slope detector
 
In direct method of fm generation armstrong method
In direct method of fm generation armstrong methodIn direct method of fm generation armstrong method
In direct method of fm generation armstrong method
 
Direct method of fm generation hartley oscillator method
Direct method of fm generation hartley oscillator methodDirect method of fm generation hartley oscillator method
Direct method of fm generation hartley oscillator method
 
Carson's rule
Carson's ruleCarson's rule
Carson's rule
 
Spectrum and power of wbfm
Spectrum and power of wbfmSpectrum and power of wbfm
Spectrum and power of wbfm
 
Narrow band frequency modulation nbfm
Narrow band frequency modulation nbfmNarrow band frequency modulation nbfm
Narrow band frequency modulation nbfm
 
General expression of fm signal
General expression of fm signalGeneral expression of fm signal
General expression of fm signal
 
Angle modulation
Angle modulationAngle modulation
Angle modulation
 
Frequency division multiplexing
Frequency division multiplexingFrequency division multiplexing
Frequency division multiplexing
 
Vsb modulation
Vsb modulationVsb modulation
Vsb modulation
 
Demodulation of ssb synchronous detector
Demodulation of ssb synchronous detectorDemodulation of ssb synchronous detector
Demodulation of ssb synchronous detector
 
Generarion of ssb phase discrimination method
Generarion of ssb phase discrimination methodGenerarion of ssb phase discrimination method
Generarion of ssb phase discrimination method
 
Generarion of ssb frequency discrimination method
Generarion of ssb frequency discrimination methodGenerarion of ssb frequency discrimination method
Generarion of ssb frequency discrimination method
 
Ssb modulation
Ssb modulationSsb modulation
Ssb modulation
 
Demodulation of dsb sc costas receiver
Demodulation of dsb sc costas receiverDemodulation of dsb sc costas receiver
Demodulation of dsb sc costas receiver
 
Quadrature carrier multiplexing qam
Quadrature carrier multiplexing qamQuadrature carrier multiplexing qam
Quadrature carrier multiplexing qam
 
Demodulation of am synchronous detector
Demodulation of am synchronous detectorDemodulation of am synchronous detector
Demodulation of am synchronous detector
 

Loops

  • 1. C Programming Language By: Yogendra Pal yogendra@learnbywatch.com Dedicated to My mother and Father
  • 2. t y Keep your notebook with you. Write important point and questions that comes in your mind Solve Mind band exercise. C Rewind when not clear Ask Questions by call or SMS or by mail Keep Watching Keep Learning THIS IS LOOPS 2
  • 3. Need • Consider a problem: – Write a program that print “Hello” 5 times. – One possible statement to solve this problem is : • printf(“Hello n Hello n Hello n Hello n Hello); – But what if we want to print “Hello” 1000 times? – We need a control structure that repeatedly execute the following statement. • printf(“n Hello);
  • 4. Decision statements • To change the control flow of a program we use: – Branching statements : cause one section of code to be executed or not executed, depending on a conditional clause. – Looping statements : used to repeat a section of code a number of times or until some condition occurs.
  • 5. Looping Statements • Allow the program to repeat a section of code any number of times untill some condition occures.
  • 6. Looping statements : 1 • while statement initial_statement; – General form: while(condition){ statement; while(condition) iteration_statement; statement; } • The program will repeatedly execute the statement inside the while until the condition becomes false (0)
  • 7. Problems • Write a program that print “Hello” 5 times. while(counter <= 5) printf(“Hello”); • This statement reads – “while counter is less than or equal to 5 print Hello ”
  • 8. Multiple Statements • Put all statements inside the curly { } braces. while(condition) { statement 1; statement 2; statement 3; }
  • 9. (I ++) or (++ I) • while (i++ < 10) – compare i with 10, – increment i. • while (++i < 10) – increment i, – compare i with 10.
  • 10. Problems • Write a program that print numbers from 1 to 100. • Write a program that print sum of 10 consecutive numbers, enter first number using keyboard. • Write a program that print all even numbers from 1 to 100. • Write a program to find the factorial value of any number entered through the keyboard.
  • 11. break statement • break statement: – Loops can be exited at any point through the use of a break statement. • Write a program that checks whether a given number is prime of not.
  • 12. continue statement • continue statement: – continue starts re-executing the body of the loop from the top. • Write a program that print numbers from 1 to 100 except the numbers that are divisible by 5 using continue statement.
  • 13. Nested while while(condition) while(condition) while(condition) { statement; while(condition) { statement; while(condition) } { } if(condition) statement; else statement; }
  • 14. Mind Bend Write a program that print all the numbers from 2 to 100 with the indication whether a number is prime of not. Output will be like: 2 : prime 3 : prime 4 : not prime
  • 15. Looping Statement : 2 • for statement • General form: for (initial_statement; condition; iteration_statement) body_statement; initial_statement; while(condition){ statement; iteration_statement; }
  • 16. Problems • Two numbers (x and y) are entered through the keyboard. Write a program to find the value of xy • Write a program that print numbers from 1 to 100 except the numbers that are divisible by 5 and 7. • Write a program to print all characters with their ASCII value. 16
  • 17. Looping Statement : 3 • do-while loop do{ statement1; statement2 }while(condition) • do-while run the statements at least once.
  • 18. Problems • Write a program that first take two numbers from user and then one operator (+, -, *, /, %) and print the result accordingly. • Now modify the above program that give an option to the user to repeat the operation again and again with different operator choosen by him.
  • 19. Mind Bend • Write a program that takes 10 floating-point numbers as a input from user and print the greatest number. • Write a program that take floating point number from user and print – ICE if it is less than 0. – WATER if it lies between 0 and 100. – STEAM if it is greater then 100. 19
  • 20. To get complete benefit of this tutorial solve all the quiz on www.learnbywatch.com For any problem in this tutorial mail me at yogendra@learnbywatch.com with the subject “C” For Other information mail at info@learnbywatch.com Keep Watching Keep Learning NEXT IS FUNCTIONS 20