Computer Science, asked by hparty383, 1 month ago

3. Write a Program in C to find the sum of the series: (Calculate the factorials using function) (b) S=1 + 1/4 + 1/9 + 1/16 + 1/25 . . .​

Answers

Answered by anindyaadhikari13
4

\textsf{\large{\underline{Solution}:}}

The given problem is solved using language - C.

#include <stdio.h>

int main() {

   float sum=0.0,i;

   int n;

   printf("Enter limit: ");

   scanf("%d",&n);

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

       sum+=1/(i*i);

   printf("Sum of the series is: %f",sum);

   return 0;

}

\textsf{\large{\underline{Explanation}:}}

  • The variable 'sum' stores the sum of the series.
  • We have asked the user enter the limit.
  • Then using a for loop, sum is calculated.

\textsf{\large{\underline{Sample I/O}:}}

#1

Enter limit: 5

Sum of the series is: 1.463611

————————————————————

#2

Enter limit: 10

Sum of the series is: 1.549768

Attachments:
Similar questions