Re: [問題] 元智91年的轉學考考古題

看板TransCSI作者 (小葉子)時間18年前 (2007/05/28 22:54), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串8/8 (看更多)
※ 引述《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
文章代碼(AID): #16MkqZ09 (TransCSI)
討論串 (同標題文章)
文章代碼(AID): #16MkqZ09 (TransCSI)