首次編程時,我必須編寫一個程序來計算系列方程 (n!)^ 2 * 2^n + 1 /(2n + 1)!,n即用戶輸入的條款數量。需要計算收斂到π的系列方程
我已經知道用戶輸入n的位置,我只能得到該號碼的答案。
如何製作它以便我可以從0到用戶輸入中獲得所有答案的總和?
#include <iostream>
#include<cmath>
using namespace std;
int main()
{
double i,n,factorial,factorial2,n2,a;
a = 1;
cout<<"Enter # of terms:";
cin>>n;
for (i = 0; i <= n; i++)
if (i == 0)
factorial = 1;
else
factorial = factorial * i;
factorial = pow(factorial,2)*pow(2,n+1);
n2 = 2*n+a;
for (i = 0; i <= n2; i++)
if (i == 0)
factorial2 = 1;
else
factorial2 = factorial2 * i;
factorial = factorial/factorial2;
cout<<factorial<<endl;
system("PAUSE");
}
等待... *什麼*不向用戶提供? – Beta 2014-10-22 05:15:54
「獲取用戶輸入的所有術語的總和?」 - 不知道你爲什麼要這樣做,但是這聽起來像'double n,total = 0; while(std :: cin >> n)total + = n; std :: cout <<「total」<< total <<'\ n';'。 – 2014-10-22 05:16:38
n條款。那麼用戶輸入爲4,得到方程中4,3,2,1和0的結果之和? – jim 2014-10-22 05:35:15