Computer Science, asked by kiranbala1072, 17 days ago

Write a program to accept two numbers and mathematical operators(+ - * / ) and perform operation accordingly.​

Answers

Answered by h146533
3

Answer:

You should have the knowledge of the following topics in c programming to understand this program.

C Arithmetic operators

C Functions

C if-else statement

C switch case statement

C main() function

C printf() function

 

There we will perform these arithmetic operations like Addition, Subtraction, Multiplication, Division, and Modulus.

Attachments:
Answered by Equestriadash
7

The following co‎des have been written using Python.

\tt n1\ =\ float(in put("Enter\ a\ number\ [N1]:\ "))\\n2\ =\ float(in put("Enter\ a\ second\ number\ [N2]:\ "))\\op\ =\ in put("Enter\ the\ desired\ mathematical\ operator:\ ")\\if\ op\ ==\ "+":\\{\ \ \ \ \ }print("You've\ chosen\ to\ add\ the\ numbers.")\\{\ \ \ \ \ }print(n1\ +\ n2,\ "is\ the\ sum\ of\ the\ numbers.")

\tt elif\ op\ ==\ "-":\\{\ \ \ \ \ }print("You've\ chosen\ to\ subtract\ the\ numbers.")\\{\ \ \ \ \ }c\ = in put("N1\ -\ N2\ or\ N2\ -\ N1?:\ ")\\{\ \ \ \ \ }if\ c\ ==\ "N1\ -\ N2"\ or\ c\ ==\ "n1\ -\ n2":\\{\ \ \ \ \ }{\ \ \ \ \ }print(n1\ -\ n2,\ "is\ the\ difference\ between\ the\ numbers.")\\{\ \ \ \ \ }else:\\{\ \ \ \ \ }{\ \ \ \ \ }print(n2\ -\ n1,\ "is\ the\ difference\ between\ the\ numbers.")

\tt elif\ op\ ==\ "*":\\{\ \ \ \ \ }print("You've\ chosen\ to\ multiply\ the\ numbers.")\\{\ \ \ \ \ }print(n1*n2,\ "is\ the\ product\ of\ the\ numbers.")

\tt elif\ op\ ==\ "/":\\{\ \ \ \ \ }print("You've\ chosen\ to\ divide\ the\ numbers.")\\{\ \ \ \ \ }c\ =\ in put("N1/N2\ or\ N2/N1?:\ ")\\{\ \ \ \ \ }if\ c\ ==\ "N1/N2"\ or\ c\ ==\ "n1/n2":\\{\ \ \ \ \ }{\ \ \ \ \ }print(n1/n2,\ "is\ the\ quotient\ of\ the\ division.")\\{\ \ \ \ \ }else:\\{\ \ \ \ \ }{\ \ \ \ \ }print(n2/n1,\ "is\ the\ quotient\ of\ the\ division.")

Once the numbers have been entered, we use conditional statements to check and perform the required operation according to the operator entered. The numbers have been set as float values if ever a decimal value is to be entered. Appropriate conditions have been given for subtraction and division as well.


Equestriadash: Thanks for the Brainliest! ^_^"
Similar questions