poj1607

来源:互联网 发布:linux访问https地址 编辑:程序博客网 时间:2024/05/01 11:40

很简单的一道题,代码如下:

 

 

#include<stdio.h>
float calculate(long x)
{
 float t;
 if(x==1)
  t=0.5;
 else
  t=calculate(x-1)+(float)1/(2*x);
 return t;
}
int main()
{
 long m;
 float res;
 printf("Cards  Overhang/n");
 while(scanf("%ld",&m)!=EOF)
 {
  res=calculate(m);
  printf("%5ld%10.3f/n",m,res);
 }
 return 0;
}

原创粉丝点击