改错题 下列给定程序中,函数FUN的功能是:按以下递归公式求函数值。
10 (n=1)
FUN(n)=
Fun(n-1)+2 (n>1)
例如,当给n输入 5时, 函数值为18,当给 n输入 3时, 函数值为14.
请改正程序中的错误,使它能得出正确结果。
注意:不要改动MAIN函数,不得增行或删行,也不要更改程序的结构!
试题程序:#include <stdio.h>
/********found********/
int fun(n)
{
int c;
/********found********/
if (n = 1)
c = 10;
else
c = fun(n-1)+2;
return (c);
}
main()
{
int n;
printf("Enter n: ");
scanf("%d", &n);
printf("The result:%d\n\n", fun(n));
}
第1处:int fun(n)应改为int fun(int n)
第2处:if (n=1)应改为if(n==1)