題目連結
https://zerojudge.tw/ShowProblem?problemid=a003
解題思路
先讀取出生月日,依據題意得到S值後,再依照S值輸出相對應的字串。
注意事項
switch()條件句是條件句之一。使用時,將想要判斷的數值或字元放在switch後面的括弧裡,並在case列出可能的情況,程式就會自動依據case指定的數字、字元或判斷句的情形,執行相對應的程式區塊。
程式碼:C語言
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| #include <stdio.h> int main() { int M, D; scanf("%d %d", &M, &D); int S = (M*2+D)%3; switch S: case 0: printf("普通"); break; case 1: printf("吉"); break; case 2: printf("大吉"); break; return 0; }
|