Sum sequence :- 1-2+3-4+5-6+7.....n
#include<stdio.h>
int main(){
int s=0;
int i,n;
printf("Enter a number : ");
scanf("%d",&n);
for (i=1; i<=n; i++){
if(i%2==0){
s=s-i;
}
else{
s=s+i;
}
}
printf("Sum = %d",s);
return 0;
}
No comments:
Post a Comment