作者ahongyeh (小叶子)
看板TransCSI
标题Re: [问题] 元智91年的转学考考古题
时间Mon May 28 22:54:26 2007
※ 引述《sss955212 (灵魂的缺角)》之铭言:
: 1. Consider the following procedure.If the argument n is 5,what will the
: procedure return?
: procedure SUM(n:integer)
: {if n=1
: return(0)
: else
: return(SUM(n-1)+n*(n-1))
: }
: 答案是 24 吗??
这题我刚刚用 TurboC 写了程式~~
跑出来是40唷~~
#include<stdio.h>
int SUM(int n)
{
if(n==1) return 0;
else return(SUM(n-1)+n*(n-1));
}
main()
{
int n;
while(1){
printf("Please in put a number: ");
scanf("%d",&n);
printf("The answer of the function is: %d\n\n\n",SUM(n));
}
}
我上传到空间去~~
可以下载来试试~~
http://w1.loxa.com.tw/ahong/knowledge/kn003.EXE
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 219.68.185.159