21、给定程序MODI1.C中函数fun的功能是:按以下递归公式求函数值。
┌ 10 (n=1)
fun(n)=┥
└ fun(n-1)+2 (n>1)
例如,当给n输入5时,函数值为18;当给n输入3时,函数值为14。
请改正程序中的错误,使它能得出正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
#include /************found************/
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));
}
| 广告合作:400-664-0084 全国热线:400-664-0084 Copyright 2010 - 2017 www.my8848.com 珠峰网 粤ICP备15066211号 珠峰网 版权所有 All Rights Reserved
|