C program to perform addition, subtraction, multiplication and division using switch case
In this program, I have discussed about the C program to perform addition, subtraction, multiplication and division using switch case
-----------------------------------------------------------------------------------
#include<stdio.h>
void main(){
char ch;
int a,b,r;
printf("Enter + or - or * or /");
scanf("%c",&ch);
printf("Enter two numbers");
scanf("%d%d",&a,&b);
switch (ch)
{
case '+':
r=a+b;
break;
case '-':
r=a-b;
break;
case '*':
r=a*b;
break;
case '/':
r=a/b;
break;
default:
printf("Invalid Input");
}
printf("Result= %d",r);
}
-------------------------------------------------------------------------------
Just copy and paste the program in your desired compiler (Dev C++ is more preferable) and run it.
Enjoy programming in C.
0 comments:
Post a Comment