# 实现五则运算

<pre><p>设计一个可以完成任意五则运算&#xff08;加法/减法/乘法/除法/取余&#xff09;的程序。除法按照计算机中<strong>整型相除</strong>来计算。
输入格式
多行输入&#xff0c;每输入一行数据对应输出一行。
每行输入格式为 a # b&#xff0c;其中 &#xff03;∈{&#43;,−,∗,/,%}
a,b均为自然数
输出格式
每行输出对应的计算结果&#xff1b;
当运算为除法/取余的时候&#xff0c;如果除数为 0 &#xff0c;输出 <code>WA</code> 。</pre>
<p>输入样例</p>
<pre>
<code>2&#43;2
4*5
6/7
4%3
4%0</code></pre>
<p>输出样例</p>
<pre>
<code>4
20
0
1
WA</code></pre>

以下程序实现了这一功能，请你补全空白处内容：

```cpp
#include <stdio.h>
int main()
{
    int a;
    int b;
    char operation;
    int num;
    while (scanf("%d", &a) != EOF)
    {
        scanf("%c", &operation);
        scanf("%d", &b);
        if (operation == '+')
        {
            num = a + b;
            printf("%d\n", num);
        }
        else if (operation == '-')
        {
            num = a - b;
            printf("%d\n", num);
        }
        else if (operation == '*')
        {
            num = a * b;
            printf("%d\n", num);
        }
        _________________________;
        else
        {
            printf("%s\n", "WA");
        }
    }
    return 0;
}
```

## template

```cpp
#include <stdio.h>
int main()
{
    int a;
    int b;
    char operation;
    int num;
    while (scanf("%d", &a) != EOF)
    {
        scanf("%c", &operation);
        scanf("%d", &b);
        if (operation == '+')
        {
            num = a + b;
            printf("%d\n", num);
        }
        else if (operation == '-')
        {
            num = a - b;
            printf("%d\n", num);
        }
        else if (operation == '*')
        {
            num = a * b;
            printf("%d\n", num);
        }
        else if (operation == '/' && b != 0)
        {
            num = a / b;
            printf("%d\n", num);
        }
        else if (operation == '%' && b != 0)
        {
            num = a % b;
            printf("%d\n", num);
        }
        else
        {
            printf("%s\n", "WA");
        }
    }
    return 0;
}
```

## 答案

```cpp
else if (operation == '/' && b != 0)
{
	num = a / b;
	printf("%d\n", num);
}
else if (operation == '%' && b != 0)
{
	num = a % b;
	printf("%d\n", num);
}
```

## 选项

### A

```cpp
else if (operation == '/')
{
	num = a / b;
	printf("%d\n", num);
}
else if (operation == '%')
{
	num = a % b;
	printf("%d\n", num);
}
```

### B

```cpp
else if (operation == '/' && b != 0)
{
	num = a / b;
	printf("%d\n", num);
}
else if (operation == '%')
{
	num = a % b;
	printf("%d\n", num);
}
```

### C

```cpp
else if (operation == '/')
{
	num = a / b;
	printf("%d\n", num);
}
else if (operation == '%' && b != 0)
{
	num = a % b;
	printf("%d\n", num);
}
```