Monday 23 May 2011

The while Loop

The second kind of loop available in C is the while loop. Here is theexample code:


included files
void main()
{
 int count=0;
 int total=0;
 clrscr();
 while(count<10)
 {
  total=total+count;
  printf("count=%d, total=%d",count++,total): 
 }
 getch();
}


The output of the program will be:
count=0, total=0
count=1, total=1
count=2, total=3
count=3, total=6
count=4, total=10
count=5, total=15
count=6, total=21
count=7, total=28
count=8, total=36
count=9, total=45




What is this?

0 comments:

Post a Comment