The While loop in C

Rate this post

It is often the case in programming that you want to do something a fixed number of times. Perhaps you want to calculate gross salaries of ten different persons, or you want to convert temperatures from centigrade to Fahrenheit for 15 different cities.

Let us look at a example which uses a while loop. The flowchart shown below would help us to understand the operation of the while loop.

while loop in c
while loop in c

/* Calculation of simple interest for 3 sets of p, n and r */
main( )
int p, n, count ;
float r, si ;

count = 1 ;

while ( count <= 3 )
printf ( “\nEnter values of p, n and r ” ) ;

scanf ( “%d %d %f”, &p, &n, &r ) ;
si = p * n * r / 100 ;

printf ( “Simple interest = Rs. %f”, si ) ;

count = count + 1;

working of while loop in c
working of while loop in c


Related Posts

  • 58
    For loop is probably the most popular looping instruction. The for allows us to specify three things about a loop in a single line: Setting a loop counter to an initial value. Testing the loop counter to determine whether its value has reached the number of repetitions desired. Increasing the value of…
    Tags: loop, learn, programming
  • 58
    Here a C program to calculate simple interest using for loop. main ( ) { int p, n, count ; float r, si ; for ( count = 1 ; count <= 3 ; count = count + 1 ) { printf ( "Enter values of p, n, and r…
    Tags: count, si, interest, simple, printf, loop, scanf, understand, values, float
  • 50
    Uses of Odd Loop In real life programming one comes across a situation when it is not known beforehand how many times the statements in the loop are to be executed. This situation can be programmed as shown below: /* Execution of a loop an unknown number of times */…
    Tags: number, loop, enter, printf, scanf, learn, programming
  • 44
    In the First C Program discussed earlier (same has been also mentioned below for the reference) we assumed the values of p, n and r to be 1000, 3 and 8.5. Every time we run the program we would get the same value for simple interest. If we want to calculate…
    Tags: values, printf, scanf, interest, simple, enter, number, si, programming, learn
  • 40
    The keyword continue allows us to take up the control to the beginning of the loop, bypassing the statements inside the loop, which have not yet been executed. When continue is encountered inside any loop, control automatically passes to the beginning of the loop. A continue is usually associated with an…
    Tags: loop, printf, main, example, int, learn, programming

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: