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

若您覺得文章寫得不錯,請點選文章上的廣告,來支持小編,謝謝。

If you like this post, please click the ads on the blog or buy me a coffee. Thank you very much.

練習一:請寫出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 language\n             will be fun.");
    return 0;
}

練習四:寫一個可以輸出菱形星星的程式
Exercise 4: Write a C program to show a diamond.

練習四參考解法:
Exercise 4 solution:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
#include <stdio.h>
#include <stdlib.h>

int main()
{
    printf("  *\n");
    printf(" ***\n");
    printf("*****\n");
    printf(" ***\n");
    printf("  *\n");
    return 0;
}

沒有留言: