Thursday 16 February 2017

while loop :

-It is an entry controlled loop statement.
-The test condition is evaluated and if the condition is true,then the body of the loop is executed.
-The execution process is repeated until the test condition becomes false and the control is transferd out of the loop.
-On exit,the program continue with the statement immediately after the body of the loop.
-This process continue until the test condition becomes false and the control is transferred out of the loop.

Syantax : 
while( test expression )
{
       Body of the loop
}
statement -x;


Program :

#include<stdio.h>
#include<conio.h>

void main();
{
int no=1,sum=0;
while(no<=100)
{
sum=sum+no;
no=no+1;
}
printf("\n sum of no's between 1 and 100:%d",sum);
getch();
}

Output :
sum of no's between 1 and 100 is:5050

No comments:

Post a Comment