hdu2011

多项式求和

http://acm.hdu.edu.cn/showproblem.php?pid=2011

   1 #include "stdio.h"
   2 void main()
   3 {
   4         int m,i,n;
   5         float sum;
   6         scanf("%d",&m);
   7         for(i=0;i<m;i++)
   8         {
   9                 sum=0;
  10                 scanf("%d",&n);
  11         
  12                 while(n>0)
  13                 {
  14                         if(n%2==1)
  15                                 sum+=1/(double)n;
  16                         else 
  17                                 sum-=1/(double)n;
  18                         n--;            
  19                 }
  20                 printf("%.2f\n",sum);
  21         }
  22 
  23 
  24 
  25 }

hdu2011 (2008-06-02 12:31:49由czk编辑)