[My site ]
Main » 2013 » December » 12 » C Programming Sheet - 4 - do while
11:26 PM
C Programming Sheet - 4 - do while
#include"stdio.h"
main()
{
int n, i=1, j=1, sum1=0, sum2=0;
printf("enter n : ");
scanf("%d", &n);
do{
sum1+=i;
i++;
if(j%2==0){
j*=-1;
}
sum2+=j;
if(j<0){
j*=-1;
}
j++;
}while(i<=n && j<=n);
printf("\nsum1 = %d\n", sum1);
printf("sum2 = %d", sum2);
getch();
}


Category: C Programming - 1 | Views: 344 | Added by: ahansaary | Rating: 0.0/0
Total comments: 0
Only registered users can add comments.
[ Sign Up | Login ]