Question

Write a C program that numerically sums up the infinite series: (1 + frac{1}{2^{2}frac{1}{3^{2}frac{1}{4^{2}+…)

EXPERT ANSWER

The below-mentioned program calculates the above-defined series up to *n* terms.

#include <stdio.h>

#include <math.h>

double sum(int n)

{

double i, s = 0.0;

for (i = 1; i <= n; i++)

s = s + 1/(pow(i,2));

return s;

}

int main()

{

int n = 0;

printf("Enter the number of terms to calculate the seriesn");

scanf("%d",&n);

printf("Sum is %f", sum(n));

return 0;

}