---
tags: DICE C
---
5-1 四則運算
===
> [name=CHAWTeam] [time=Feb 16, 2022]
---
目錄:[DICE C語言程式破解](https://hackmd.io/@CHAWTeam/DiceC)
上一篇:[4_4 印出資料](https://hackmd.io/@CHAWTeam/DiceC-4_4)
下一篇:[5-2 餘數](https://hackmd.io/@CHAWTeam/DiceC-5-2)
---
題目
---
```!
寫一個程式,輸入2個整數,印出兩數加、減、乘、除的結果。
輸入範例:
5
2
輸出範例:
5+2=7
5-2=3
5*2=10
5/2=2餘1
c範例程式:
#include <stdio.h>
int main()
{
int num1,num2; /*宣告二個整數變數*/
scanf("......",......,......); /*輸入兩個整數變數*/
printf("...+...=...\n",...,...,...+...); /*加*/
printf("...-...=...\n",...,...,...-...); /*減*/
printf("...*...=...\n",...,...,...*...); /*乘*/
printf(".../...=.餘.\n",...,...,.../...); /*除與取餘數*/
return 0;
}
c++範例程式:
#include<iostream>
using namespace std;
int main()
{
int num1,num2;/*宣告二個整數變數*/
cin>>num1>>num2;/*輸入兩個整數變數*/
cout<<num1<<"+"<<num2<<"="<<num1+num2<<endl;/*加*/
cout<<num1<<"-"<<num2<<"="<<num1-num2<<endl;/*減*/
cout<<num1<<"*"<<num2<<"="<<num1*num2<<endl;/*乘*/
cout<<num1<<"/"<<num2<<"="<<num1/num2<<"餘"<<num1%num2<<endl;/*除與取餘數*/
return 0;
}
```
### 提示
![](https://i.imgur.com/F2gwSku.png)
程式碼
---
```c=
#include <stdio.h>
int main()
{
int num1, num2;
scanf ("%d %d", &num1, &num2);
printf("%d+%d=%d\n", num1, num2, num1+num2);
printf("%d-%d=%d\n", num1, num2, num1-num2);
printf("%d*%d=%d\n", num1, num2, num1*num2);
printf("%d/%d=%d\n", num1, num2, num1/num2);
return 0;
}
```
輸出
---
```!
5
2
5+2=7
5-2=3
5*2=10
5/2=2餘1
```
---
[查看我們在HackMD上的所有筆記](https://hackmd.io/@CHAWTeam)
目錄:[DICE C語言程式破解](https://hackmd.io/@CHAWTeam/DiceC)
上一篇:[4_4 印出資料](https://hackmd.io/@CHAWTeam/DiceC-4_4)
下一篇:[5-2 餘數](https://hackmd.io/@CHAWTeam/DiceC-5-2)
---
{%hackmd Iiu5mOixR7yWkPHKCkabBg %}
<iframe class="LikeCoin" height="235" src="https://button.like.co/in/embed/chawteam/button?referrer=https://hackmd.io/@CHAWTeam/DiceC-5-1" width="100%"></iframe>
---
{%hackmd i1nMRrZcTFmTvoF897K9zg %}