看板 SCU-BM-88C 關於我們 聯絡資訊
※ 引述《reallyice (WEN)》之銘言: : #include<stdio.h> : #include<conio.h> : #include<stdlib.h> : Void main(void) : { : int A,B,C,D,R; : clrscr(); : randomize(); : A=1; : B=1; : D=3; : R=random(數字)+1; : if(R==1) : { : printf("%i",A); : } : else : { : if(R==2) : { : printf("%i,%i",A,B); : } : else : { : printf("%i,%i",A,B); : while(D<=R) : { : C=A+B; : A=B; : B=C; : D=D+1; : printf(",%i",C); : } : } : } : } : 以上如有問題, : 請洽4G美宣部reallyice, : 或4G活動部stt。 結果為 1 1,1 1,1,2 1,1,2,3 1,1,2,3,5 1,1,2,3,5,8 1,1,2,3,5,8,13 1,1,2,3,5,8,13,21 意思為 當R=1時 PRINTF出1 當R=2時 PRINTF出1,1 當R!=1及R!=2時 執行 while(D<=R) { C=A+B; A=B; B=C; D=D+1; printf(",%i",C); } 意思為 一開始為 D=3 A=1 B=1 C=A+B 則C=2 printf is 1,1,2 if D<=R 繼續做下一次 A=B B=C C=A+B 此時 A=1 B=2 C=A+B 則C=3 printf is 1,1,2,3 依此類推 -- 我是一個屬於山的孩子 我喜歡化做雲漂泊在天空 吹起捲向理想之地的清風 瞭望著遠方美麗的夢