C++

C and C++ classic example of the simulated calculator sample code


preface

This paper mainly introduces the use of C/C++ how to achieve the simulation of the calculator related content, to share out for your reference learning, the following words do not say, to 1 look at the detailed introduction.

Problem Description

Simple calculator simulation: input two integers and one operator, output operation results.

Input

Enter two integers in line 1, separated by Spaces.

Line 2 enters an operator (+, -, *, /).

All operations are integer operations, ensuring that the divisor does not contain a 0.

Output

Output the result of an operation on two Numbers.

Example Input

30 50
*

Example Output

import java.util.Scanner;

public class Main {
  public static void main(String args[]){
   Scanner reader = new Scanner(System.in);
   int m,n;
   String a = "+",b = "-",c="*",d = "/";
   String s;
   m = reader.nextInt();
   n = reader.nextInt();

   s = reader.next();
   switch(s){
   case"+":System.out.println(m+n);break;
   case"-":System.out.println(m-n);break;
   case"*":System.out.println(m*n);break;
   case"/":

    System.out.println(m/n);
   break;

   }
  }

  }

conclusion