以下教學取自附件的C語言教學內容(資料取自網路)
一、基本輸出輸入/算術運算式
範例一:求圓周長及面積
http://blockly-demo.appspot.com/static/apps/code/index.html?lang=en#9ueih2
習作:
1、 已知球體半徑 r ,請計算球體體積 V。並輸出至小數點後 3 位數。
2、 已知攝氏溫度 C ,請轉換為華氏溫度 F ,並輸出至小數點後 1 位數。
3、 已知有台幣 NT 元,請兌換為美金 US 元,並輸出至小數點後 3 位數。
範例二:計算一元二次方程式: ax^2 +bx+c = 的兩個根
http://blockly-demo.appspot.com/static/apps/code/index.html?lang=en#22nayy
習作:
1、 已知三角形三邊長a, b,c,請利用海龍公式求三角形面積 area,並輸出至小數點 3 位數。
海龍公式:
s = ( a + b + c) / 2;
area = sqrt ( s * (s‐a) * (s‐b) * (s‐c) );
二、選擇敘述句
範例三:判斷是否有實數解(範例二的延伸:無實數解(D<0)、有兩相等實根(D=0)、兩相異實根(D>0))
習作:
2、 請輸入一個任意整數,由電腦輸出此數為奇數還是偶數。
【範例輸入】:4
【範例輸出】:偶數
http://blockly-demo.appspot.com/static/apps/code/index.html?lang=en#45dqv3
3、 試寫一程式,輸入 x、y 座標值,可判斷此點位於那一個象限或是在座標軸上。
【範例輸入】:3.0, ‐2.5
【範例輸出】:(3.0, ‐2.5)在第四象限上
【範例輸入】:4.5, 0.0
【範例輸出】:(4.5, 0.0)在 x軸上
http://blockly-demo.appspot.com/static/apps/code/index.html?lang=en#x7cejp
4、 請輸入任意三個數值,由電腦輸出此三數是否可構成一個三角形。
【範例輸入】:3,4,5
【範例輸出】:可
【範例輸入】:1,2,3
【範例輸出】:否
三、迴圈敘述句(for..)
範例四:利用迴圈印出數列 1‐7
http://blockly-demo.appspot.com/static/apps/code/index.html?lang=en#8nkxtx
習作:
1、印出 3, 8, 13, 18, 23
2、印出 20, 14, 8, 2, ‐4, ‐10
範例五:印出 sin(x) 從 0 度到 360 度的值
http://blockly-demo.appspot.com/static/apps/code/index.html?lang=en#vge72v
習作:
2、改寫上述程式,計算 cos(x) 0 度 到 180 度的值。每10 度印出結果。
範例六:找出 N 的所有因數
http://blockly-demo.appspot.com/static/apps/code/index.html#y2pyu4
習作:
3、輸入任意整數 N ,請檢驗此數是否為質數。
註:質數是除了1與本身外,沒有其他的因數
四、迴圈敘述句—while/do..while
範例七:猜數字遊戲
http://blockly-demo.appspot.com/static/apps/code/index.html#2nkrfv
習作:
4、請完成上述程式,讓它可以順利變成遊戲程式。要可以重複猜,應將do…while 包住那一段程
式碼呢?
5、將程式改成可以猜 1 – 42 的數,應如何改寫呢?
範例八:計算學生平均
http://blockly-demo.appspot.com/static/apps/code/index.html?lang=en#k4y6z5
習作:
1、請準備一陣列,可存放100 個整數值。利用for 迴圈,將產生的亂數值寫入陣列中。
提示:
int arrayA[100]; //宣告一個可存放100 個整數的陣列 arrayA
srand( time(NULL) );
for ( num = 0; num<100; num++)
{
arrayA[num] = rand(); //將產生出來的亂數存入 arrayA 中。
}
http://blockly-demo.appspot.com/static/apps/code/index.html?lang=en#ciqjy9
範例十:列出費伯納基數列的前n 個數值
費伯納基數列:
1 1 2 3 5 8 13 21… 若 fn 表示第 n 項,則 fn = fn‐1 + fn‐2 (n>=2)
如何以for 迴圈,將數列中的值逐項計算出來?
http://blockly-demo.appspot.com/static/apps/code/index.html?lang=en#6v74ig
六、陣列—二維陣列(無此功能)
七、函數
範例十三:練習寫函數,可以計算f(x)= x^2+5x+8 的值