C Program to Implement Calculator Using Switch Case

C Program to Implement Calculator Using Switch Case

Write C Program to Implement Calculator Using Switch Case

//WAP to implement calculator using Switch case

#include <stdio.h>

int main()
{
	int n1, n2, x, sum,sub,mul,div;

	printf("Enter the options as follows: \n1.Addition \n2.Subtraction \n3.Multiplication \n4.Division");
	printf("\nYour Option :--> ");
	scanf("%d", &x);

	printf("Enter the number 1 :--> ");
	scanf("%d", &n1);

	printf("Enter the number 2 :--> ");
	scanf("%d", &n2);


	switch(x)
    {
        case 1:
        	sum = n1 + n2;
            printf("%d + %d = %d", n1, n2, sum);
            break;

        case 2:
            sub = n1 - n2;
            printf("%d - %d = %d", n1, n2, sub);
            break;

        case 3:
        	mul = n1 * n2;
            printf("%d * %d = %d", n1, n2, mul);
            break;

        case 4:
            div = n1 / n2;
            printf("%d / %d = %d", n1, n2, div);
            break;


        default:
        	printf("Please enter the correct input");
        	break;
    }
	return 0;
}

Output:

Run 1:
Enter the options as follows:
1.Addition
2.Subtraction
3.Multiplication
4.Division

Your Option :--> 3

Enter the number1 :--> 56
Enter the number2 :--> 2

56 * 2 = 112

Run 2:
Enter the options as follows:
1.Addition
2.Subtraction
3.Multiplication
4.Division

Your Option :--> 1

Enter the number1 :--> 56
Enter the number2 :--> 2

56 + 2 = 58