Computer Science, asked by vijay4574, 1 year ago

write a program to read two numbers and perform all mathematical operations and print result of those operations


Anonymous: shud I do in JAVA ??
vijay4574: yes
Anonymous: k let me answer it :)
vijay4574: matlab

Answers

Answered by Anonymous
1

JAVA CODE  


import java.util.*;


class subtract_numbers


{


public static void main(String args[ ])


{


Scanner sc=new Scanner (System.in);


System.out.println("Enter 2 numbers to carry out subtraction");


int a=sc.nextInt();


int b=sc.nextInt();


int c= a-b;


System.out.println("Difference="+c);


int d=a+b;


System.out.println("Sum="+d);


int e=a*b;


System.out.println("Product="+e);


int f=a/b;


System.out.println("Quotient="+f);


}//end of main


}//end of class

-------------------------------------------------------


Hope it helps !

______________________________________________________________


Anonymous: I don't know C++ but wait I am asking someone to help you ........
vijay4574: ok thanks
vijay4574: help me
Anonymous: yep wait a little .....
vijay4574: fast
vijay4574: help me fast
Anonymous: k wait
vijay4574: please
Anonymous: someone is answering ur question wait plz
vijay4574: ok
Answered by siddhartharao77
3

Sample Program in C++:

#include<iostream>

using namespace std;

int main()

{

char result;

float num1,num2;

cout << "Enter an operator\n";

cin >> result;

cout << "Enter two numbers:\n";

cin >> num1 >> num2;

switch(result)

{

case '+':

cout << num1 + num2;

break;

case '-':

cout << num1 - num2;

break;

case '*':

cout << num1 * num2;

break;

case '/':

cout << num1 / num2;

break;

default:

printf("Incorrect");

}

return 0;

}


Note: In some cases, num1 > num2.. You can write it using if else condition.


Output:

Please select an Operator:

+

Enter two numbers:

10 20

30.


Hope it helps!

Attachments:

vijay4574: help this
Similar questions