I'm solving the question, Given an integer N. Calculate the sum of series 13 + 23 + 33 + 43 + … till N-th term.
I write this code but it can't add the first recursive function call solution.
Ex -
N = 5 and the Answer is 1^3+2^3+3^3+4^3+5^3=225. but it gives me 224, it doesn't add the first 1, Is any changes required here?
using namespace std;
long long calSum(long long i,long long n)
{
int sum = 0;
if (i > n)
return 0;
sum = pow(i,3);
return sum + calSum(i + 1,n);
}
int main()
{
int n;
cin >> n;
cout << calSum(1,n) <<endl;
return 0;
}