- 2072 Kartik · 5 marks
Sum of series Σ1/n²
Short answer
Sum 1/i^2 for i=1 to N using double (1.0/(i*i)). With N=10, the result is 1.549768.
Write a program to find the sum of series Sn = Σ 1/n² up to N term.
The series is Sn = 1/1² + 1/2² + 1/3² + ... + 1/N². The program adds 1/(i*i) for i = 1 to N. A double and the real constant 1.0 are used so that the division is not an integer division (which would give 0).
#include <stdio.h>
int main(void)
{
int n, i;
double sum = 0.0;
printf("Enter number of terms: ");
scanf("%d", &n);
for (i = 1; i <= n; i++)
sum += 1.0 / ((double)i * i);
printf("Sn = %.6f\n", sum);
return 0;
}
Output for N = 10:
Enter number of terms: Sn = 1.549768
(The sum tends to π²/6 = 1.6449 as N becomes large.)
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- GOTO types; sum of series program · Computer Programming, chapter 11
- Cosine series up to n terms · Computer Programming, chapter 5
- Series sum 1/1¹+1/2²+… in FORTRAN · Computer Programming, chapter 11
- nth Fibonacci term prime check · Computer Programming, chapter 6
- Series 1+11+111+… by recursion · Computer Programming, chapter 6
- Series (2*3/5)+(4*5/7)+… with functions · Computer Programming, chapter 6
- C program: sum of two 8-bit BCD numbers · Embedded System, chapter 9
- Series sum using Z-transform · Mathematics III, chapter 3
- Voltage build-up; series generator at no load · Electrical Machines, chapter 3
- LandMeasure class and sum function · Object Oriented Programming, chapter 4