do{ Statements ---------- } while(condition); next statements...
#include⁢stdio.h> main() { int a,s=0; printf("Enter numbers"); do { scanf("%d",&a); s=s+a; }while(a!=0); printf("sum is %d",s); }
Enter a number 5 2 3 6 0 Sum is 16
#include⁢stdio.h> main() { int a,s=0; printf("Enter numbers"); do { scanf("%d",&a); if(a%2==0) s=s+a; }while(a!=0); printf("sum of even is %d",s); }
Enter a number 5 2 7 6 0 Sum of even is 8
#include⁢stdio.h> main() { int a,s1=0,s2=0; printf("Enter numbers"); do { scanf("%d",&a); if(a%2==0) s1=s1+a; else s2=s2+a; }while(a!=0); printf("sum of all even no. is %d\n",s1); printf("sum of all odd no. is %d",s2); }
Enter a number 2 5 8 3 6 0 sum of all even no. is 16 sum of all odd no. is 8
#include⁢stdio.h> main() { int a,c1=0,c2=0; printf("Enter numbers"); do { scanf("%d",&a); if(a>0) c1=c1+1; if(a ⁢ 0) c2=c2+1; }while( a!=0); printf("Total positive no. are %d\n",c1); printf("Total negative no. are %d",c2); }
Enter a number 2 -5 8 -3 6 0 Total positive no. are 3 Total negative no. are 2