1+1/2+2/3+3/5+5/8…前10项之和 C语言编写
1+1/2+2/3+3/5+5/8…前10项之和 C语言编写
日期:2011-05-12 13:42:46 人气:1
#include
int main(void)
{
int i;
float n = 1.0, m = 1.0, sum = 0.0, tmp;
for (i = 1; i <= 10; i++)
{
sum += m / n;
tmp = m;
m = n;
n += tmp;
}
printf("前十项和是%f\n", sum);
r