Problem statement:
Write a C program to take two numbers and operator as input then perform arithmatic operation depending on input operator.
Write a C program to perform arithmetic operations on two numbers using switch case
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
#include<stdio.h> int main() { int n,m,t; char c; printf("Enter two numbers and operator :\n"); scanf("%d %d %c", &n, &m, &c); switch(c) { case '+' : printf("Addition is : %d", n+m); break; case '-' : printf("Substraction is %d", n-m); break; case '*' : printf("Multiplication is %d", n*m); break; case '/' : printf("Division is %f", (float)n/m); break; default : printf("Not valid"); } getch(); return 0; } |
Output
1 2 3 |
Enter two numbers and operator : 2 8 / Division is 0.250000 |