L4_T1

 avatar
unknown
c_cpp
3 years ago
532 B
4
Indexable
#include <iostream>
#include <cmath>

using namespace std;

double RecursiveSum(double x, int i, int n)
{
    //cout << 2.0 / pow(x + i, 3) << '-' << i <<  endl;
    return i < n ? (2.0 / pow(x + i, 3) + RecursiveSum(x, i + 1, n)) : 0;
}

int main()
{   
    double x;
    int n;
    int i = 1;
    while(true)
    {
        cout << "enter x and n: " << endl;
        cin >> x >> n;
        if(x > 0 && n > 0) break;
        cout << "Incorrect input values!";
    }
    cout << "Sum = "<< RecursiveSum(x, i, n);
    
    return 0;
}
Editor is loading...