while(condition) { statements ---------- ---------- } next statements
#include⁢stdio.h> main() { int i=1; while(i<=10) { printf("%d ",i); i++; } }
1 2 3 4 5 6 7 8 9 10
#include⁢stdio.h> main() { int i=10; while (i>=1) { printf("%d ",i); i--; } }
10 9 8 7 6 5 4 3 2 1
#include⁢stdio.h> main() { int i=10; while(i<=20) { printf("%d\n",i); i++; } }
10 11 12 13 14 15 16 17 18 19 20
#include⁢stdio.h> main() { int i=1; while(i<=100) { printf("%d ",i); i=i+2; } }
#include⁢stdio.h> main() { int i=1; while(i<=100) { if(i%2==0 || i%3==0) printf("%d ",i); i++; } }
#include⁢stdio.h> main() { int i=1; while(i<=10) { printf("Amravati\n"); i++; } }
Amravati Amravati Amravati Amravati Amravati Amravati Amravati Amravati Amravati Amravati
#include⁢stdio.h> main() { int a,i=1,s=0; while(i<=10) { printf("Enter a Number "); scanf("%d",&a); s=s+a; i++; } printf("Sum is %d",s); }
Enter a number 5 Enter a number 6 Enter a number 2 Enter a number 9 Enter a number 3 Enter a number 4 Enter a number 1 Enter a number 7 Enter a number 8 Enter a number 3 Sum is 48
#include⁢stdio.h> main() { int a,i=1,s1=0,s2=0; printf("Enter 10 Numbers "); while(i<=10) { scanf("%d",&a); if(a%2==0) s1=s1+a; else s2=s2+a; i++; } printf("Sum of Even Numbers is %d",s1); printf("\nSum of Odd Numbers is %d",s2); }
Enter a number 5 Enter a number 6 Enter a number 2 Enter a number 9 Enter a number 3 Enter a number 4 Enter a number 1 Enter a number 7 Enter a number 8 Enter a number 3 Sum of even nos is 20 Sum of odd nos is 28