练习2-9 整数四则运算 (10 分)

练习2-9 整数四则运算 (10 分)

本题要求编写程序,计算2个正整数的和、差、积、商并输出。题目保证输入和输出全部在整型范围内。

输入格式:

输入在一行中给出2个正整数A和B。

输出格式:

在4行中按照格式“A 运算符 B = 结果”顺序输出和、差、积、商。

输入样例:

3 2

输出样例:

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;
}

 

猜你喜欢

转载自www.cnblogs.com/xxl-h/p/11110767.html
今日推荐