解:最简单的源程序如下:
include
#define END 20
void main()
{
float sum=0,t=2;
int i=0;
while(i++
sum+=t;
t=1+1/t;
}
printf("%f\n",sum);
}
不用解释吧,你自己模拟运行一下就知道了!
#include
#include
double foo(int counter) {
double i, j, sum;
for(i = 1., j = 2., sum = 0.; counter > 0; j += i, i = j - i, counter--) {
sum += j / i;
}
return sum;
}
int main(int argc, char* argv) {
printf("%lf", foo(20));
getch();
return 0;
}
二楼的解优