[問題] c++ 無窮級數的計算

看板C_and_CPP作者 (pacific hero)時間15年前 (2009/04/11 20:09), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
問題: │x^(2i)│ 請寫一個程式計算下列級數的收斂值,收斂條件為│───│<10^(-6) │(2i)! │ ∞ x^(2i) 級數為Σ ──── i=0 (2i)! 在下寫的 #include<iostream> #include<cmath> using namespace std; int main() { double x,i,t=1,s=1; cout<<"請輸入x的值"; cin>>x; for(i=1;t>fabs(1.0e-6);i++) { t=t*x*x/(2*i*(2*i-1)); s=s+t; } cout<<"所求="<<s; return 0; } 煩請板上高手撥冗看一下有沒有錯誤.... 感激不盡.... -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.229.68.234
文章代碼(AID): #19u8YKO1 (C_and_CPP)