The series is: 1-2+3-4+5-6+7-8...N terms, we have to find out the sum up to Nth terms.
Let's analyse this problem,
If we want Sum of this series up to 2nd term then sum will be:
Up to 3rd term:
Up to 4th term
1-2+3-4 = -2
Up to 5th term:
Now we can conclude that if we want sum up to an Odd term then we always get sum as ((N+1)/2) and if we want sum up to an Even term the sum is in the form of (-1*(N/2)).
Now Let's make logic for this using c programming,
//function for creating the sum of the
//series up to Nth term
int series_sum(int n)
if (n % 2 == 0)
return (-(n / 2));
return ((n + 1) / 2);
// main code
printf("Want some up to N terms?\nEnter the N term:");
printf("Sum is:%d", series_sum(n));
Want some up to N terms?
Enter the N term:10
total answers (1)
start bookmarking useful questions and collections and save it into your
own study-lists, login now to start creating your own collections.