---
# System prepended metadata

title: 7-1 比大小
tags: [DICE C]

---

---
tags: DICE C
---

7-1 比大小
===

> [name=CHAWTeam]

---

目錄：[DICE C語言程式破解](https://hackmd.io/@CHAWTeam/DiceC)
上一篇：[6-5 預算夠不夠？](https://hackmd.io/@CHAWTeam/DiceC-6-5)
下一篇：[7-2 三數比大小](https://hackmd.io/@CHAWTeam/DiceC-7-2)

---

題目
---

```!
輸入兩個正整數a、b，輸出兩數中較大的值。
此題可以執行2次，
建議：輸入一組測資，得到結果，再將程式碼複製。

輸入範例1:
20 10

輸出範例1:
最大值20

輸入範例2:
17 19

輸出範例2:
最大值19

c範例程式:
#include <stdio.h>
int main()
{
int a,b,max;
scanf("......",......);
max=a;   /*指定max值為a*/
if(......){   /*如果b>a，則更新max值*/
   max=b;
}
printf("......\n",......);
/*第二輪判斷*/
scanf("......",......);
max=a;   /*指定max值為a*/
if(......){   /*如果b>a，則更新max值*/
   max=b;
}
printf(".....\n",......);
return 0;
}

c++範例程式:
#include <iostream>
using namespace std;
int main()
{
int a,b,max;
cin>>a>>b;
max=a;
if(b>max){
   max=b;
}
cout<<"最大值"<<max<<endl;
/*第二輪判斷*/
cin>>a>>b;
max=a;
if(b>max){
   max=b;
}
cout<<"最大值"<<max<<endl;
return 0;
}
```

程式碼
---

```c=
#include <stdio.h>

int main()
{
    int a, b, max;
    
    scanf("%d %d", &a, &b);
    max = a;
    if (b > a)
        max = b;
    printf("最大值%d\n", max);
    
    /*第二輪判斷*/
    scanf("%d %d", &a, &b);
    max = a;
    if (b > a)
        max = b;
    printf("最大值%d\n", max);
    
    return 0;
}
```

輸出
---

```!
20 10
最大值20
17 19
最大值19
```

---

[查看我們在HackMD上的所有筆記](https://hackmd.io/@CHAWTeam)
目錄：[DICE C語言程式破解](https://hackmd.io/@CHAWTeam/DiceC)
上一篇：[6-5 預算夠不夠？](https://hackmd.io/@CHAWTeam/DiceC-6-5)
下一篇：[7-2 三數比大小](https://hackmd.io/@CHAWTeam/DiceC-7-2)

---

{%hackmd Iiu5mOixR7yWkPHKCkabBg %}
<iframe class="LikeCoin" height="235" src="https://button.like.co/in/embed/chawteam/button?referrer=https://hackmd.io/@CHAWTeam/DiceC-7-1" width="100%"></iframe>

---

{%hackmd i1nMRrZcTFmTvoF897K9zg %}