天天看點

杭電acm 1012

//雖然這道題自己一次ac但是還是覺得acm的輸出格式要特别注意
#include<iostream>
using namespace std;
int jiecheng(int n)
{
 if(n==1)
 return 1;
 else
 return n*jiecheng(n-1);
}
int main()
{
 int n=9;
 double res=1.0;
 cout<<"n e"<<endl;
 cout<<"- -----------"<<endl;
 cout<<"0 1"<<endl;
 for(int i=1;i<=n;i++)
 {
  res+=1.0/jiecheng(i);
  cout<<i<<" ";
  if(i<3)
   cout<<res<<endl;  //cout會自動優化輸出結果 預設小數點後6位,但是如果後面為0,則就不再顯示
  else
   printf("%.9f\n",res); //可以友善的控制輸出結果格式
  
 }
 return 0;
}
           
ACM