下列给定程序中函数fun的功能是:求出如下分数序列的前n项之和,和值通过函数值返回。
例如,若n=5,则应输出8.391667。
请改正程序中的错误,使其得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
试题程序:
#include <stdlib.h>
#include <conio.h>
#include <stdio.h>
/**********found**********/
void fun(int n)
{
int a=2, b=1, c, k;
double s=0.0;
for(k=1; k<=n; k++)
{
/**********found**********/
s=s+(Double)a/b;
c=a;a=a+b;b=c;
}
return(s);
}
void main()
{
int n=5;
system("CLS");
printf("\nThe value of function is:% 1f\n", fun(n));
}