Aim: Find the sum of the series S = 1 + (1/2)2 + (1/3)3 +…. to 0.0001% accuracy.
#include <math.h>
#include <stdio.h>
int main()
{
int n,i;
double sums = 0.0, ser;
printf("Enter n: ");
scanf("%d",&n);
for (i = 1; i <= n; ++i) {
ser = 1 / pow(i, i);
sums += ser;
}
printf("%.5f", sums);
return 0;
}
Output
Enter n: 2 Sum = 1.25000
