标签:style blog color io os for strong sp div
题意
求n=0~9时的sigma(1/n!)
分析
因为刚学c++ 所以对浮点操作还是很不熟练,正好来了这么一道题
Accepted Code
1 /* 2 PROBLEM:hdu 1012 3 AUTHER:Nicole Lam 4 MEMO:水题 5 */ 6 #include<iostream> 7 #include<iomanip> 8 using namespace std; 9 double a[10]; 10 int main() 11 { 12 cout<<"n e"<<endl; 13 cout<<"- -----------"<<endl; 14 a[0]=1; 15 double temp=1.0; 16 cout<<"0 1"<<endl; 17 for (int i=1;i<=9;i++) 18 { 19 temp=temp*i; 20 a[i]=a[i-1]+(double)1/temp; 21 if (i==1) cout<<"1 2"<<endl; 22 else if (i==2) cout<<"2 2.5"<<endl; 23 else cout<<i<<" "<<fixed<<setprecision(9)<<a[i]<<endl; 24 } 25 return 0; 26 }
标签:style blog color io os for strong sp div
原文地址:http://www.cnblogs.com/NicoleLam/p/4038944.html