Calculate the expression:
1/a +1/(a+1) +..+ 1/((a+1)...(a + n))Example:
Input:
2 1
Output:
0.666667Example:
Input:
2.1 2
Output:
0.667266
#include <iostream>
using namespace std;
int main()
{
int n = 0, i;
double a = 0, s, d;
cin >> a >> n;
s = 1.0 / a;
for (i = 1; i < n + 1; i++) {
a = a * (a + i);
s = s + 1.0 / a;
}
cout << s << endl;
return 0;
}
Не могли бы вы помочь найти, где у меня ошибка?