Compile and run the program
Save the changes made to main.cpp
file and run the following command in your terminal:
g++ main.cpp -o main && ./main
After successful compilation and run, it will ask the user to enter the value of N. After entering the value of N, the program will return the sum of the series.
Full code of main.cpp
file:
#include <iostream>
#include <cmath>
using namespace std;
double findsum(int N) {
double sum = 0;
for(int i=1; i<=N; i++) {
sum += pow((double)1/i,i);
}
return sum;
}
int main() {
int N;
cout << "Enter the value of N: ";
cin >> N;
double sum = findsum(N);
cout << "Sum of the series is: " << sum << endl;
return 0;
}