Friday, September 11, 2009

While Loop

The while loop is ideally suited for case in programming that you want to do something
a fixed number of times.
Sample Program
/* 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;
}
}

The program executes all statements after while 3 times.

No comments:

Post a Comment

 
GetBlogs Blog Directory BrowseBlogs.com Subscribe to updates