---
tags: DICE C
---
7-2 三數比大小
===
> [name=CHAWTeam]
---
目錄:[DICE C語言程式破解](https://hackmd.io/@CHAWTeam/DiceC)
上一篇:[7-1 比大小](https://hackmd.io/@CHAWTeam/DiceC-7-1)
下一篇:[7-3 五數比大小](https://hackmd.io/@CHAWTeam/DiceC-7-3)
---
題目
---
```!
寫一個程式,輸入3個整數,輸出最大值與最小值,格式如範例輸出所示。
此題可以執行2次,
建議:輸入一組測資,得到結果,再將程式碼複製。
輸入範例1:
3 2 1
輸出範例1:
最大值3
最小值1
輸入範例2:
6 8 5
輸出範例2:
最大值8
最小值5
```
程式碼
---
### 範例1
```c=
#include <stdio.h>
int main()
{
int a, b, c, max, min;
scanf("%d %d %d", &a, &b, &c);
if (b > a && b > c)
{
max = b;
if (a > c)
min = c;
else if (c > a)
min = a;
}
else if (a > b && a > c)
{
max = a;
if (b > c)
min = c;
else if (c > b)
min = b;
}
else if (c > b && c > a)
{
max = c;
if (b > a)
min = a;
else if (a > b)
min = b;
}
printf("最大值%d\n", max);
printf("最小值%d\n", min);
/*第二輪判斷*/
scanf("%d %d %d", &a, &b, &c);
if (b > a && b > c)
{
max = b;
if (a > c)
min = c;
else if (c > a)
min = a;
}
else if (a > b && a > c)
{
max = a;
if (b > c)
min = c;
else if (c > b)
min = b;
}
else if (c > b && c > a)
{
max = c;
if (b > a)
min = a;
else if (a > b)
min = b;
}
printf("最大值%d\n", max);
printf("最小值%d\n", min);
return 0;
}
```
輸出
---
```!
3 2 1
最大值3
最小值1
6 8 5
最大值8
最小值5
```
---
[查看我們在HackMD上的所有筆記](https://hackmd.io/@CHAWTeam)
目錄:[DICE C語言程式破解](https://hackmd.io/@CHAWTeam/DiceC)
上一篇:[7-1 比大小](https://hackmd.io/@CHAWTeam/DiceC-7-1)
下一篇:[7-3 五數比大小](https://hackmd.io/@CHAWTeam/DiceC-7-3)
---
{%hackmd Iiu5mOixR7yWkPHKCkabBg %}
<iframe class="LikeCoin" height="235" src="https://button.like.co/in/embed/chawteam/button?referrer=https://hackmd.io/@CHAWTeam/DiceC-7-2" width="100%"></iframe>
---
{%hackmd i1nMRrZcTFmTvoF897K9zg %}