write a program of calculater in java,c,c++,java script, python language.
Answers
Answer:
Program of calculator in python .
Explanation:
Python Program:-
# This function adds two numbers
def add(x, y):
return x + y
# This function subtracts two numbers
def subtract(a, b):
return a - b
# This function multiplies two numbers
def multiply(a, b):
return a × b
# This function divides two numbers
def divide(a , b):
return
print("Select operation.")
print("1.Add")
print("2.Subtract")
print("3.Multiply")
print("4.Divide")
# Take input from the user
choice1 = input("select (1/2/3/4):")
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
Answer:
This is a simple program of calculator in C programming using switch statement.
Explanation:
#include <stdio.h>
int main() {
char op;
double first, second;
printf("Enter an operator (+, -, *,): ");
scanf("%c", &op);
printf("Enter two numbers: ");
scanf("%lf %lf", &first, &second);
switch (op) {
case '+':
printf("%.1lf + %.1lf = %.1lf", first, second, first + second);
break;
case '-':
printf("%.1lf - %.1lf = %.1lf", first, second, first - second);
break;
case '*':
printf("%.1lf * %.1lf = %.1lf", first, second, first * second);
break;
case '/':
printf("%.1lf / %.1lf = %.1lf", first, second, first / second);
break;
default:
printf("Wrong typing dear");
}
return 0;
}