# 第二題 ## 題目說明 1. 左上App標題名稱為『 Fibonacci Sequence 』 2. 第一個按鈕(Button)標題『費氏數列計算』如圖三所示,按下後可將【文字方塊一】(TextBox)、內之費氏數列項數對應的值計算出,並將其值於【文字方塊二】中呈現出。 3. 【文字方塊一】,用以輸入費氏數列的項數,並於【文字方塊二】,二進位數字輸出文字方塊呈現。  ## 介面  ## 程式 ### button1_Click ```csharp private void button1_Click(object sender, EventArgs e) { textBox2.Text = fib(Convert.ToInt32(textBox1.Text)).ToString(); int f0 = 0; int f1 = 1; int f2 = f0+f1; } ``` 定義f0和f1,然後呼叫fib來計算函式 ### fib ```csharp private int fib(int num) { if(num==0) { return 0; } if(num==1) { return 1; } else { return fib(num-1)+fib(num-2); } } ``` 定義num,然後進行計算
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up