• IO-02. 整数四则运算


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

    输入格式:

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

    输出格式:

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

    输入样例:
    3 2
    输出样例:
    3 + 2 = 5
    3 - 2 = 1
    3 * 2 = 6
    3 / 2 = 1

    C语言代码实现:

     1 #include <stdio.h>
     2 
     3 int main()
     4 {
     5     int a,b;
     6     
     7     scanf("%d %d", &a, &b);
     8     printf("%d + %d = %d
    ", a, b, a+b);
     9     printf("%d - %d = %d
    ", a, b, a-b);
    10     printf("%d * %d = %d
    ", a, b, a*b);
    11     printf("%d / %d = %d
    ", a, b, a/b);
    12         
    13     return 0;
    14 }

     Java代码实现:

     1 import java.util.Scanner;
     2 
     3 public class Main {
     4     public static void main(String[] args) {
     5         int a, b;
     6         Scanner s1 = new Scanner(System.in);
     7         a = s1.nextInt();
     8         b = s1.nextInt();
     9         System.out.println(a + " + " + b + " = " + (a + b));
    10         System.out.println(a + " - " + b + " = " + (a - b));
    11         System.out.println(a + " * " + b + " = " + (a * b));
    12         System.out.println(a + " / " + b + " = " + (a / b));
    13     }
    14 }
  • 相关阅读:
    BZOJ 1055 [HAOI2008]玩具取名
    BZOJ 1054 [HAOI2008]移动玩具
    BestCoder Round #51 (div.2)
    python对拍程序
    BZOJ 1053 [HAOI2007]反素数ant
    BZOJ 1051 [HAOI2006]受欢迎的牛
    Codeforces Round #315 (Div. 2)
    今天愉快的hack小记
    BZOJ 1050 [HAOI2006]旅行comf
    COJ 2135 Day10-例1
  • 原文地址:https://www.cnblogs.com/ConciseAaron/p/3769084.html
Copyright © 2020-2023  润新知