首页 > 代码库 > 近似计算

近似计算

#include<stdio.h>                                                     
int main()                                                            
{                                                                     
 double s=0, si,i;                                                    
 int n;                                                               
    for(int i=0;;i++)                                                 
 {                                                                    
  double term=1.0/(i*2+1);if(i%2==0)                                  
   if(i%2==0)                                                         
    s+=term;                                                          
   else s-=term;                                                      
   if(term<1e-6)break;                                                
  }                                                                   
  printf("%.6lf\n",s);                                                
  return 0;                                                           
}                                                                     
                                                                      

近似计算