# C++ program to find the sum of the series 1 + 1/2^2 + 1/3^3 + …..+ 1/n^n

C++Server Side ProgrammingProgramming

#### C in Depth: The Complete C Programming Guide for Beginners

45 Lectures 4.5 hours

#### Practical C++: Learn C++ Basics Step by Step

Most Popular

50 Lectures 4.5 hours

#### Master C and Embedded C Programming- Learn as you go

66 Lectures 5.5 hours

In this tutorial, we will be discussing a program to find the sum of the given series 1 + 1/2^2 + 1/3^3 + …..+ 1/n^n.

For this, we will be given with the value of n and our task is to add up every term starting from the first one to find the sum of the given series.

## Example

#include <iostream>
#include <math.h>
using namespace std;
//calculating the sum of the series
double calc_sum(int n) {
int i;
double sum = 0.0, ser;
for (i = 1; i <= n; i++)
ser = 1/ pow(i, i);
sum += ser;
return sum;
}
int main() {
int n = 5;
double res = calc_sum(n);
cout << res << endl;
return 0;
}

## Output

0.00032
Updated on 09-Jul-2020 08:51:51