• Write a program to print the sum of the first n terms of the following series
1/2 - 1/4 + 16 -1/8 +...
Answers
Answered by
0
Answer:
void sum (int terms)
{
float sum = 0.0, j = 1.0;
int count;
for(count = 1; count <= terms; count++)
{
sum = sum + (1/j);
if(count%2 == 0)
j = j * (-2);
else
j = j * 2;
}
printf("\nSum of Series:\t %f", sum);
printf("\n");
return 0;
}
int main () {
int numberOfTerms = 5;
sum(numberOfTerms);
return 0;
}
Explanation:
Hope this helps
Similar questions