×
☰ Menu

 

 

 

 

Code:

#include<stdio.h>
#include<conio.h>
int main()
{
int i=1;
while(i<=10)
{
printf("%d\n",i);
i=i+1;
}
getch();
return 0;
}

Output

1
2
3
4
5
6
7
8
9
10

--------------------------------
Process exited after 46.28 seconds with return value 0
Press any key to continue . . .

 


nested while loop

 

 

 

Code:

#include<stdio.h>
#include<conio.h>
int main( ) 
{ 
int r, c, sum ;
r = 1 ;
while(r <= 3) /* outer loop */ 
     { 
       c = 1 ; 
       while(c <= 2)/* inner loop */       
           { 
           sum = r + c ; 
           printf ( "r = %d c = %d sum = %d\n", r, c, sum ) ;
           c++;
           }
       r++;
     }     
getch();
}

Output:

r = 1 c = 1 sum = 2
r = 1 c = 2 sum = 3
r = 2 c = 1 sum = 3
r = 2 c = 2 sum = 4
r = 3 c = 1 sum = 4
r = 3 c = 2 sum = 5

--------------------------------
Process exited after 6.337 seconds with return value 0
Press any key to continue . . .