0
1.1kviews
Write a program to implement calculator with following operations using switch case

b. Subtract two numbers

c. Multiply two numbers

d. Divide two numbers

0
13views

Program:

#include<stdio.h>
#include<conio.h>

int main() {
float a,b,c;
int d;
char c;
clrscr();

printf("\n\n\t Simple Calculator");
fflush(stdin);

printf("\n\n\t Enter + Add - Sub * Mul / div % div(R)");
scanf("%c", &c1);

switch(c1) {
case '+':
printf("\n\n\t Enter two numbers");
scanf("%f %f", &a, &b);
c = a + b;
break;

case '-':
printf("\n\n\t Enter two numbers");
scanf("%f %f", &a, &b);
c = a - b;
printf("\n\n\t Subtraction = %f", c);
break;

case '*':
printf("\n\n\t Enter two numbers");
scanf("%f %f", &a, &b);
c = a * b;
printf("\n\n\t Multiplication = %f", c);
break;

case '/':
printf("\n\n\t Enter two numbers");
scanf("%f %f", &a, &b);
c = (int)a / (int)b;
printf("\n\n\t Division (Q) = %d", c);
break;

case '%':
printf("\n\n\t Enter two numbers");
scanf("%f %f", &a, &b);
c = (int)a % (int)b;
printf("\n\n\t Division (R) = %d", c);
break;

default:
printf("\n\n\t Invalid Input");
}

getch();
return 0;
}