练习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


 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 
 4 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
 5 
 6 int main(int argc, char *argv[]) {
 7 int a,b,c,d,e,f;
 8 
 9 scanf("%d %d",&a,&b);
10 
11 c=a+b;
12 d=a-b;
13 e=a*b;
14 f=a/b;
15 
16 printf("%d + %d = %d
",a,b,c);
17 printf("%d - %d = %d
",a,b,d);
18 printf("%d * %d = %d
",a,b,e);
19 printf("%d / %d = %d
",a,b,f);
20 return 0;
21 }
 
 
原文地址:https://www.cnblogs.com/xxl-h/p/11110767.html