编写1+1/2+1/3+…+1/n计算程序
#include"stdio.h"
void main()
{
int i=1,n;
float sum=0;
printf(“please input the n:\n”);
scanf("%d",&n);
while(i<=n)
{
sum+=1.0/i;
i++;
}
printf(“the result is %.5f\n”,sum);
}
编写1+1/2+1/3+…+1/n计算程序
#include"stdio.h"
void main()
{
int i=1,n;
float sum=0;
printf(“please input the n:\n”);
scanf("%d",&n);
while(i<=n)
{
sum+=1.0/i;
i++;
}
printf(“the result is %.5f\n”,sum);
}