MiaoMiao
unread,Jan 13, 2008, 7:25:33 AM1/13/08Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to 程序=数据结构+算法
#include <stdio.h>
double
foo(int n)
{
int i;
double result=1,u=1,d=1;
if(1==n)return 1;
for(i=1;i<n;++i){
double t=d;
d=u;
u=d+t;
result+=u/d;
}
return result;
}
int
main(void)
{
int n;
while(EOF!=(fscanf(stdin,"%d",&n))){
fprintf(stdout,"%.3lf\n",foo(n));
}
return 0;
}