c语言求解热传导

sum is2.000000
sum is3.500000
sum is5.166667
sum is6.766666
sum is8.391666
sum is 10.007051
sum is 11.626099
sum is 13.243746
sum is 14.861928
sum is 16.479906
sum is 18.097961
sum is 19.715986
sum is 21.334023
sum is 22.952055
sum is 24.570089
sum is 26.188124
sum is 27.806158
sum is 29.424192
sum is 31.042227
sum is 32.660259
Press any key to continue
#include <stdio.h>
main()
{
int n,t,number=20;
float a=2,b=1,s=0;
for(n=1;n<=number;n++)
{
s=s+a/b;
t=(int)a;
a=a+b;
b=(float)t;
printf("sum is %9.6f\n",s);
}
}

#include <stdio.h>
int qh(int n)
{
int i,j,t,sum;
sum=0;
i=1;j=2;
while()/*本题的算法,后项的分母是前项的分子,后项的分子是前项的分子和分母之和*/
{t=1.0*j/i;
sum+=t;
i=j;
j=i+j;/*你的记录我没弄明白,要每步输出的话,加个输出语句 。*/
}
}
void main()
{
intn, sum;
sum=0;
scanf("%d\n",&n);
sum=qh(n);
printf("%d\n",sum);
}
骨架已给出,楼主需补下循环条件 。。。。

递推就是知道前后项的关系,从结果一步一步推出初始,或从开始推出结果 。
分子和分母的关系是第三项是前两项的和

#include <stdio.h>
main()
{
int sum=0;
int i;
for(i=1;i<=20;i++)
{
sum+=i;
printf("%d/%d\n",sum,i);
}
}

2/1 ,3/2, 5/3, 8/5 这些数有什么规律或者要求么【c语言求解热传导】

    推荐阅读