Skip to content

Instantly share code, notes, and snippets.

@rsmahmud
Created January 6, 2017 17:04
Show Gist options
  • Save rsmahmud/c4a475c191c741699715f8133ae62438 to your computer and use it in GitHub Desktop.
Save rsmahmud/c4a475c191c741699715f8133ae62438 to your computer and use it in GitHub Desktop.
#include<stdio.h>
int main(){
int i,n,c=1,sum=0;
printf("\n Last number of series : ");
scanf("%d",&n);
if(n>0 && n%2){
printf("\n Series = ");
for(i=1; i<(n/2)+2; i++){
if(i==1)printf("1");
else printf(i%2?"+%d":"-%d",c);
i%2 ? sum += c : (sum -= c);
c+=2;
}
printf("\n\n Sum = %d\n",sum);
}
else
printf("\n Number must be positive and odd\n");
fflush(stdin);
getch();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment