c程序设计第四版谭浩强
有一分数序列:2/1,3/2,5/3,8/5,13/8,21/13...求出这个数列的前20项之和。
c程序设计(第四版)学习辅导 谭浩强 编著
【c源程序】
#include <stdio.h>
int main()
{
int i,n=20;
double a=2,b=1,s=0,t;
for (i=1;i<=n;i++)
{
s=s+a/b;
t=a,
a=a+b,
b=t;
}
printf("sum=%16.10f\n",s);
return 0;
}
本文链接:http://www.wb98.com/c/post/tanhaoqiang_5.10.html
本站文章搜索: