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

a. Add two numbers

b. Subtract two numbers

c. Multiply two numbers

d. Divide two numbers

1 Answer
0
14views

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;
            printf("\n\n\t Addition = %f", c);
            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;
}
Please log in to add an answer.