Make a Calculator Using Switch Case in C Programming

How to make an easy calculator of four operations ( + , – , * , / ) by using switch case in c programming.

Codes are here….

Let see the codes

#include<stdio.h>
int main()
{
int a,b,c,result;
char operator;

printf("enter your choice\n1=+\n2=-\n3=*\n4=/\n");
scanf("%c",&operator);

printf("enter two numbers\n");
scanf("%d%d",&a,&b);

switch(operator)
    {
    case'1':
        result=a+b;
        break;
    case'2':
        result=a-b;
        break;
    case'3':
        result=a*b;
        break;
    case'4':
        result=a/b;
        break;
    default:
        printf("\nyou have entered blank option");
    }

printf("\nresult is =%d",result);   
getchar();
}

Output:

enter your choice
1=+
2=-
3=*
4=/
1
enter two numbers
10
20
result is =30
[Process completed - press Enter]

Let see in C Programming softwere….

Page: 1
Page: 2
Page: 3

Output:

Output

Leave a comment