Exercise 2-9 Integer Arithmetic (10 minutes)

Exercise 2-9 Integer Arithmetic (10 minutes)

This problem requires programming, calculates two positive integers, difference, product, quotient and outputs. Title ensure that all inputs and outputs in the range of integers.

Input formats:

Input given two positive integers A and B. in a row

Output formats:

4 in the format line "A operator B = Result" and sequentially output, the difference, product, quotient.

Sample input:

3 2

Sample output:

3 + 2 = 5
3 - 2 = 1
3 * 2 = 6
3 / 2 = 1


 

#include <stdio.h>
#include <stdlib.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[]) {
int a,b,c,d,e,f;

scanf("%d %d",&a,&b);

c=a+b;
d=a-b;
e=a*b;
f=a/b;

printf("%d + %d = %d\n",a,b,c);
printf("%d - %d = %d\n",a,b,d);
printf("%d * %d = %d\n",a,b,e);
printf("%d / %d = %d\n",a,b,f);
return 0;
}

 

Guess you like

Origin www.cnblogs.com/xxl-h/p/11110767.html