7-10 Addition, subtraction, multiplication and division

7-10 Addition, subtraction, multiplication and division

topic

For the two input integers, output the sum-difference quotient as required.
Input format:

Enter two non-negative integers a and b not exceeding 100 in a line, separated by a space in the middle, and ensure that b is not 0.
Output format:

A total of four lines, the format is:

[a] + [b] = [a+b]
[a] - [b] = [a-b]
[a] * [b] = [a*b]
[a] / [b] = [a/b]

Among them, the content with square brackets (such as [a], [b], [a + b], etc.) represents the corresponding integer or the value of the operation result, and the actual value should be replaced when output.

And: if a is divisible by b, then a / b should be output in integer format, otherwise a / b is output in a format with two decimal places.

Tip: Pay attention to the spaces in the expression.
Sample input:

6 3

Sample output:

6 + 3 = 9
6 - 3 = 3
6 * 3 = 18
6 / 3 = 2

Code

#include<stdio.h>

int main(){
	int a,b,sum,minus,multiply,quotient,point;
	scanf("%d %d",&a,&b);
	if(a<=100 && a>=0 && b>0 && b<=100){
		sum=a+b;
		printf("%d + %d = %d\n",a,b,sum);
		minus=a-b;
		printf("%d - %d = %d\n",a,b,minus);
		multiply=a*b;
		printf("%d * %d = %d\n",a,b,multiply);
		quotient=a*100/b;
		point=quotient%100;
		quotient/=100;
		if(point==0){
			printf("%d / %d = %d\n",a,b,quotient);
		}else{
			printf("%d / %d = %d.%d\n",a,b,quotient,point);
		}
	}
	return 0;
} 
Published 21 original articles · praised 0 · visits 39

Guess you like

Origin blog.csdn.net/weixin_47127378/article/details/105565826