C中函数的应用

#include<stdio.h>
double funa(int m)
{
double s;
int t;
s=1.0;
for(t=2;t<=m;t++)
	s+=1.0/t;    //1必须加小数点写成1.0//
	return s;
}
void main()
{int m;
double sum;
scanf("%d",&m);
sum=funa(m);
printf("hewei=%lf",sum);//双精度的表示lf,即long float

 getchar();
 getchar();
 getchar();
 getchar();
 }

注意:使用双精度变量,做运算需要在常量上加小数点,否则计算结果不正确。

猜你喜欢

转载自blog.csdn.net/qq_18671205/article/details/89196066