看板 TransCSI 關於我們 聯絡資訊
※ 引述《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