11:26 PM C Programming Sheet - 4 - while |
#include"stdio.h"
main()
{
int n, i=1, j=1, sum1=0, sum2=0;
printf("enter n : ");
scanf("%d", &n);
while(i<=n && j<=n){
sum1+=i;
i++;
if(j%2==0){
j*=-1;
}
sum2+=j;
if(j<0){
j*=-1;
}
j++;
}
printf("\nsum1 = %d\n", sum1);
printf("sum2 = %d", sum2);
getch();
}
|
|
Total comments: 0 | |