All pastes #615673 Raw Edit

Stuff

public text v1 · immutable
·published 2007-07-12 07:41 UTC
rendered paste body
int factorial(int num) {
   if (num == 1)
      return 1;

   return factorial(num-1) * num;
}

void CalcEtoPI(ofstream&fout)
{ 
     double total=1.0;
     for(double x=1.0; x<=20.0; x+=1.0)
     { 
      const double PI=3.14;
      double newterm;
      
      newterm=1.0/factorial(x)*pow(PI,x);
      
      total=total+newterm;    
        
      fout<<total<<endl;
      cout<<total<<endl;  
      
     }     
    
  
}


output:
4.14
9.0698
14.2297
18.2801
20.8239
22.1551
22.7522
22.9866
23.0683
23.094
23.1014
23.1033
23.1048
23.1118
23.126
23.1706
22.1987
21.2186
46.4353
42.3055

Press any key to terminate