Computer Science, asked by doris23, 1 year ago


22. Input 2 numbers and also Input your choice if your choice is 1 then Addition of two numbers. if your choice
is 2 then Subtractions of two numbers, if your choice is 3 then Multiplication of two numbers, if your choice
is 4 then Division of two numbers in c++ if program

Answers

Answered by tejasvarshney
0

Import java.util.*;

class number

{

public static void main();

 {

 Scanner in = new Scanner (System.in);

 int n1, n2, c, a;

           

               System.out.println(“Enter any two number”);

  n1 = in.nextInt();

               n2 = in.nextInt();

 System.out.println(“Enter your choice”)

 c = in.nextInt();

 switch(c)

 {

  case 1:

                       a = n1 + n2;

  System.out.printn(“sum of two number = “  +a);

  case 2:

  a = n1 – n2;

  System.out.println(“Subtraction of two number = ” + a);

  case 3:

  a = n1 * n3;

  System.out.println(“Multiplication of two number =  ” + a);

   

  case 4:

  a = n1 / n2;

  System.out.println(“Division of two number = ” + a);

  default:

  System.out.println(“Wrong Choice”);

 }

}

}

or this program can be written in this form also

Import java.util.*;

class number

{

public static void main();

 {

 Scanner in = new Scanner (System.in);

 int n1, n2, c, a;

           

System.out.println(“Enter any two number”);

  n1 = in.nextInt();

          n2 = in.nextInt();

 System.out.println(“Enter your choice”)

 c = in.nextInt();

 if (c == 1)

  {

   a = n1 + n2;

   System.out.println(“Addition of two number =” + a);

  }

 else if(c == 2)

  {

   a = n1 – n2;  

System.out.println(“Substraction of two number =” + a);

  }

 else if (c == 3)

  {

   a  =  n1 * n2;

System.out.println(“multiplication of two number =” + a);

  }

 else if (c == 4)

  {

   a = n1 / n2;

   System.out.println(“division of two number =” + a);

  }

 else  

  {

   System.out.println(“Wrong Choice”);

  }

 }

}

Similar questions