Created
January 6, 2017 17:04
-
-
Save rsmahmud/c4a475c191c741699715f8133ae62438 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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