C 語言練習題:玩玩 printf
2 min readOct 1, 2020
練習一:請寫出C語言程式碼的骨架
Exercise 1: What is the skeleton of a C program?
練習一參考解法:
Exercise 1 solution:
#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:
#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:
#include <stdio.h>
#include <stdlib.h>int main()
{
printf("Hi!\n\n");
printf("Let's get started!\n");
printf("Learning\n C language\n will be fun.");
return 0;
}
練習四:寫一個可以輸出菱形星星的程式
Exercise 4: Write a C program to show a diamond.
練習四參考解法:
Exercise 4 solution:
#include <stdio.h>
#include <stdlib.h>int main()
{
printf(" *\n");
printf(" ***\n");
printf("*****\n");
printf(" ***\n");
printf(" *\n");
return 0;
}
Originally published at https://yunlinsong.blogspot.com.