C语言中的整型参数m用于计算以下公式:y=1/(2)+1/(4)+…+1/(2*m);若采用循环,则需使用for loop
发布时间
阅读量:
阅读量
例如:当m的数值设定为9时,相应的输出结果应当为1.414484。
#include "stdio.h"
void TestFunc();
double fun(int m)
{ /**********Begin**********/
double y=0;
int i;
for(i=1; i<=m; i++)
{y+=1.0/(2*i); }
return(y);
/********** End **********/
}
void main()
{ int n;
printf("Enter n: ");
scanf("%d", &n);
printf("\nThe result is %1f\n", fun(n));
TestFunc();
}
全部评论 (0)
还没有任何评论哟~
