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

 

For any query or issue, feel free to discuss on http://discuss.eduguru.in

Leave a Reply

%d bloggers like this: