Computer Science, asked by omegads03, 1 year ago

WAP to design a calculator?

Answers

Answered by tiyabanerjee72p8f7f5
1

use switch case

in menu give list

1. press 1 for addition

and like that

then case 1

a=b+c

where b and c are inputed by user and so on

Answered by MrGame00
0

Hey User !

=) xample: Simple Calculator using switch Statement

// Performs addition, subtraction, multiplication or division depending the input from user

# include <stdio.h>

int main() {

char operator;

double firstNumber,secondNumber;

printf("Enter an operator (+, -, *,): ");

scanf("%c", &operator);

printf("Enter two operands: ");

scanf("%lf %lf",&firstNumber, &secondNumber);

switch(operator)

{

case '+':

printf("%.1lf + %.1lf = %.1lf",firstNumber, secondNumber, firstNumber + secondNumber);

break;

case '-':

printf("%.1lf - %.1lf = %.1lf",firstNumber, secondNumber, firstNumber - secondNumber);

break;

case '*':

printf("%.1lf * %.1lf = %.1lf",firstNumber, secondNumber, firstNumber * secondNumber);

break;

case '/':

printf("%.1lf / %.1lf = %.1lf",firstNumber, secondNumber, firstNumber / secondNumber);

break;

// operator doesn't match any case constant (+, -, *, /)

default:

printf("Error! operator is not correct");

}

return 0;

}

Hope , It Helps ...

Similar questions