#include <stdio.h>
#include <stdlib.h>
int main()
{
int t,n,b;
float sum,h=1;
scanf("%d",&n);
for(t=1;t<=n-1;t++)
{
for(b=1,sum=1;b<=t;b++)
{
h=h+2;
sum+=1/h;
}
h=1;
}
printf("%.3f",sum);
}
本文提供了一个使用C语言实现的简单程序示例,该程序通过嵌套循环计算特定数学序列的累加和,并展示如何处理浮点数运算。文章包括了完整的源代码及说明。
#include <stdio.h>
#include <stdlib.h>
int main()
{
int t,n,b;
float sum,h=1;
scanf("%d",&n);
for(t=1;t<=n-1;t++)
{
for(b=1,sum=1;b<=t;b++)
{
h=h+2;
sum+=1/h;
}
h=1;
}
printf("%.3f",sum);
}
1万+

被折叠的 条评论
为什么被折叠?
