這一題有兩解法,一種用if , else if , else ,另一種利用 switch case
--------------------< 法一 >--------------------------
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[])
{
int M , D , S;
scanf("%d %d",&M,&D);
S=(M*2+D)%3;
if(S==0)
{
printf("普通\n");
}
else if(S==1)
{
printf("吉\n");
}
else
{
printf("大吉\n");
}
system("PAUSE");
return 0;
}
------------------------<法二>--------------------------------
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[])
{
int M , D , S;
scanf("%d %d",&M,&D);
S=(M*2+D)%3;
switch (S)
{
case 0:
printf("普通\n");
break;
case 1:
printf("吉\n");
break;
case 2:
printf("大吉\n");
break;
}
system("PAUSE");
return 0;
}
---------------------------解釋------------------------------------
資料型別與變數 → 輸入輸出(scanf / printf)→ 運算子 → 條件判斷(if-else 或 switch)。