---
tags: DICE C
---
10-3 逛牛墟
===
> [name=CHAWTeam]
目錄:[DICE C語言程式破解](https://hackmd.io/@CHAWTeam/DiceC)
題目
---
```!
目前台灣僅存鹽水、善化與北港有牛墟,當然牛墟已不進行牛隻買賣的交易,而是市集的型態存在。其規則如下,
日期末位數是1, 4或7, 則牛墟在鹽水
日期末位數是2, 5或8, 則牛墟在善化
日期末位數是3, 6或9, 則牛墟在北港
日期末位數是0, 則本日沒有牛墟
超過32,則是超出範圍
請輸入日期,判斷該日的牛墟狀況,本程式可以執行4次
輸入範例:
21
20
32
15
輸出範例:
21日在鹽水
20日沒有
32日超出範圍
15日在善化
```
程式碼
---
```c=
#include <stdio.h>
int main()
{
int x;
scanf("%d", &x);
if (x < 32)
{
if (x % 10 == 1 || x % 10 == 4 || x % 10 == 7)
printf("%d日在鹽水\n", x);
else if (x % 10 == 2 || x % 10 == 5 || x % 10 == 8)
printf("%d日在善化\n", x);
else if (x % 10 == 3 || x % 10 == 6 || x % 10 == 9)
printf("%d日在北港\n", x);
else if (x % 10 == 0)
printf("%d日沒有\n", x);
}
else
printf("%d日超出範圍\n", x);
scanf("%d", &x);
if (x < 32)
{
if (x % 10 == 1 || x % 10 == 4 || x % 10 == 7)
printf("%d日在鹽水\n", x);
else if (x % 10 == 2 || x % 10 == 5 || x % 10 == 8)
printf("%d日在善化\n", x);
else if (x % 10 == 3 || x % 10 == 6 || x % 10 == 9)
printf("%d日在北港\n", x);
else if (x % 10 == 0)
printf("%d日沒有\n", x);
}
else
printf("%d日超出範圍\n", x);
scanf("%d", &x);
if (x < 32)
{
if (x % 10 == 1 || x % 10 == 4 || x % 10 == 7)
printf("%d日在鹽水\n", x);
else if (x % 10 == 2 || x % 10 == 5 || x % 10 == 8)
printf("%d日在善化\n", x);
else if (x % 10 == 3 || x % 10 == 6 || x % 10 == 9)
printf("%d日在北港\n", x);
else if (x % 10 == 0)
printf("%d日沒有\n", x);
}
else
printf("%d日超出範圍\n", x);
scanf("%d", &x);
if (x < 32)
{
if (x % 10 == 1 || x % 10 == 4 || x % 10 == 7)
printf("%d日在鹽水\n", x);
else if (x % 10 == 2 || x % 10 == 5 || x % 10 == 8)
printf("%d日在善化\n", x);
else if (x % 10 == 3 || x % 10 == 6 || x % 10 == 9)
printf("%d日在北港\n", x);
else if (x % 10 == 0)
printf("%d日沒有\n", x);
}
else
printf("%d日超出範圍\n", x);
return 0;
}
```
輸出
---
```!
21
20
32
15
21日在鹽水
20日沒有
32日超出範圍
15日在善化
```
---
[查看我們在HackMD上的所有筆記](https://hackmd.io/@CHAWTeam)
目錄:[DICE C語言程式破解](https://hackmd.io/@CHAWTeam/DiceC)
---
{%hackmd Iiu5mOixR7yWkPHKCkabBg %}
<iframe class="LikeCoin" height="235" src="https://button.like.co/in/embed/chawteam/button?referrer=https://hackmd.io/@CHAWTeam/DiceC-10-3" width="100%"></iframe>
---
{%hackmd i1nMRrZcTFmTvoF897K9zg %}