發表文章

C語言練習題:scanf 輸入(C language exercise: input with scanf )

圖片
練習一:大小寫轉換 讓使用者輸入小寫字母,程式轉成大寫字母。 讓使用者輸入大寫字母,程式轉成小寫字母。 Exercise 1: Case converter Take a lowercase letter from the user and convert it to uppercase letter. Take a uppercase letter from the user and convert it to lowercase letter. 練習一參考解法: Exercise 1 solution: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 #include <stdio.h> #include <stdlib.h> int main () { char letter, small, large; printf( "Please input a small letter:" ); scanf( " %c" , & small); letter = small + ( 'A' - 'a' ); printf( "Large letter is %c \n " , letter); printf( "Please input a large letter:" ); scanf( " %c" , & large); letter = large + ( 'a' - 'A' ); printf( "Small letter is %c \n " , letter); return 0 ; } 練習二:數學式 輸入4個整數a, b, c, d,求出(a + b) * (c + d)的結果。 Exercise 2: Equation Get four integers a, b, c, d from the user. Calculate (a + b) * (c + d) and ...

C語言練習題:資料型別與變數(C language exercise: data type and variables)

圖片
練習一:變數的賦值 請分別賦值給三個變數x = 111, y = 222, z = 333; 然後輸出此三個變數的總和與乘積。 Exercise 1: Variable assignment Assign values to the variables x = 111, y = 222, z = 333; Then, print the sum, the product of these three variables. 練習一參考解法: Exercise 1 solution: 1 2 3 4 5 6 7 8 9 10 #include <stdio.h> #include <stdlib.h> int main () { int x = 111 , y = 222 , z = 333 ; printf( "%d + %d + %d = %ld \n " , x, y, z, (x + y + z)); printf( "%d * %d * %d = %ld \n " , x, y, z, (x * y * z)); return 0 ; } 練習二: ASCII 數值 設計一個程式可以輸出 'A'、'a'、'0'、'#' 的 ASCII的數值 Exercise 2:  ASCII  Values Design a C program to to display the ASCII values of these symbols: 'A', 'a', '0', '#'  練習二參考解法: Exercise 2 solution: 1 2 3 4 5 6 7 8 9 10 11 12 #include <stdio.h> #include <stdlib.h> int main () { printf( "%c in ASCII: %d \n " , 'A' , 'A' ); printf( ...

C 語言練習題:玩玩 printf (C language exercise: play with printf)

圖片
練習一:請寫出C語言程式碼的骨架 Exercise 1: What is the skeleton of a C program? 練習一參考解法: Exercise 1 solution: 1 2 3 4 5 6 7 8 9 10 11 12 #include <stdio.h> #include <stdlib.h> int main () { /* * * Here is your code. */ return 0 ; } 練習二:寫一個程式可以輸出"開始學C語言囉!" Exercise 2: Write a program to print the message: "Start learning C language!"  練習二參考解法: Exercise 2 solution:  1 2 3 4 5 6 7 8 9 #include <stdio.h> #include <stdlib.h> int main () { printf( "開始學習C語言囉!" ); printf( "Start learning C language!" ); return 0 ; } 練習三:(換行)請用換行符號 "\n" 輸出下圖上的文字 Exercise 3:  Using new line character "\n" to display this picture message. 練習三參考解法: Exercise 3 solution: 1 2 3 4 5 6 7 8 9 10 #include <stdio.h> #include <stdlib.h> int main () { printf( "Hi! \n\n " ); printf( "Let's get started! \n " ); printf( "Learning \n C la...

MakeCode Microbit 遊戲設計:「接雞蛋」(Microbit Game: Egg Catching)

圖片
小編曾做過 Scratch 遊戲:接雞蛋 ,而且最近剛好看到Youtube 上的影片: Micro:bit 創意遊戲:「接水果 」 。於是來教大家自己用Microbit來做一個玩玩吧。The blog post:  Scratch 遊戲:接雞蛋  created a egg-catching game. And there is a video on youtube:  Micro:bit 創意遊戲:「接水果 」 . So, this post will create a Microbit game: Egg Catching. 首先來分析影片中遊戲的功能有哪些: Game design: 角色「player」(就是玩家你囉),位在最下方的紅點。Player will be at (x, y) = (2, 4) when the game is started. 角色「egg」(從天而降的雞蛋),位於上方不停落下的紅點。Egg will be at (x, y) = (pick random 0 to 4, 0) when the game is started. A按鈕將「player」角色往左移動一格。When the A button is pressed, player moves to the left. B按鈕將「player」角色往右移動一格。When the B button is pressed, player moves to the right. 「player」角色接到「egg」角色時,會有動畫與音效,並得一分。When the player catches the egg, score 1 and perform some animation and play a melody. 雞蛋落到地面三次時,遊戲結束,並顯示Game Over,以及總得分。When the egg fall to the ground three times, the game is over. Show "Game Over" and total score on the screen. 製作步驟 Steps 步驟零:開啟 Makecode Microbit Editor (Step 0: open Makecode Microbit ...

雲造研習紀錄:USB手搖充電式手電筒

圖片
2020/09/19 小編參加雲造所舉辦的研習【USB手搖充電式手電筒】,此文為小編的筆記與心得記錄。 【USB手搖充電式手電筒】介紹影片: 材料與電路圖: 單獨檢測個別電子材料,這很重要,因為等焊接好後,再來檢測有沒有問題時,就已經太遲了。 小編的成品 心得:小編的焊接技巧尚需加強。此課程適合給已經懂點電路的學生喔! 若您覺得文章寫得不錯,請點選文章上的廣告,來支持小編,謝謝。 If you like this post, please click the ads on the blog or  buy me a coffee . Thank you very much.

Microbit 遊戲設計:誰是快手高手(Microbit Game Design: Who's The Fastest Clicker)

圖片
本篇文章將講解如何製作一個簡易的兩人按鈕競賽遊戲:誰是快手高手。 This article will create a simple two players microbit game: Who's the fastest clicker.  一、遊戲功能如下(Game Design): 遊戲開始時將球放在LED矩陣正中央的x,y座標(2, 2)上。Light up the LED at (2,2) when the game started. 按下A按鈕時,球往左移動。The ball moves to the left when the button A is pressed. 按下B按鈕時,球往右移動。The ball moves to the right when the button B is pressed. 碰到牆壁時,有兩種情況:There are two conditions when the ball hits the edge: 1. 左邊牆壁,球的x座標等於0時,球的y座標減 1 ,球的x座標設為4。Left edge: when the ball's x equals to 0, ball's y minus 1 and assign ball's x to 4. 2. 右邊牆壁,球的x座標等於4時,球的y座標加 1 ,球的x座標設為0。Right edge: when the ball's x equals to 4, ball's y plus 1 and assign ball's x to 0. 當球的座標為(0,0)或(4,4)時,遊戲結束。When the ball is in (0,0) or (4,4), the game is over. 二、積木程式(Blocks Code) 遊戲開始時將球放在LED矩陣正中央的x,y座標(2, 2)上。Light up the LED at (2,2) when the game started. 按下A按鈕時,球往左移動。The ball moves to the left when the button A is pressed. 碰到左邊牆壁,球的x座標等於0時,球的y座標減 1 ,球的x座標設為4。Left edge: w...

Microbit 遊戲設計:猜數字遊戲(Microbit: Number Guessing Game)

圖片
本篇文章將講解如何製作一個簡易的猜數字遊戲。 This post introduces how to create a simple number-guessing game with Microbit. 一、遊戲功能如下:The game functions: 遊戲一開始自動產生一個 0 - 9 的數字讓使用者猜猜看。Pick a random from 0 to 9 when the game starts.  A 按鈕使用者猜數字,每按一次則加 1。Plus one to user's guess when button A is pressed. B 按鈕使用者猜數字,每按一次則減 1。Minus one to user's guess when button B is pressed. A + B 按鈕比較結果,使用者猜對時,遊戲重頭開始。When button A and button B are pressed, check the result. If the user's guess is correct, the game restarts. 二、積木程式 The Blocks 先使用 Make a Variable 來建立兩個變數: answer 與 guess 。 Click  Make a Variable  to create two variables: answer  and  guess . 遊戲一開始自動產生一個 0 - 9 的數字讓使用者猜猜看。  Pick a random from 0 to 9 when the game starts.  A 按鈕使用者猜數字,每按一次則加 1。 Plus one to user's guess when button A is pressed. B 按鈕使用者猜數字,每按一次則減 1。 Minus one to user's guess when button B is pressed. A + B 按鈕比較結果,使用者猜對時,遊戲重頭開始。 When button A and button B are pressed, check the result. If the user's guess is correc...