WAP that takes two operands and one operator from the user and perform the operation and prints the result by using Switch statement.
#include <stdio.h> #include <conio.h> void main() { int a, b, c; char ch; clrscr() ; printf("Enter your operator(+, -, /, *, %)\n"); scanf("%c", &ch); printf("Enter the values of a and b\n"); scanf("%d%d", &a, &b); switch(ch) { case '+': c = a + b; printf("addition of two numbers is %d", c); break; case '-': c = a - b; printf("substraction of two numbers is %d", c); break; case '*': c = a * b; printf("multiplication of two numbers is %d", c); break; case '/': c = a / b; printf("remainder of two numbers is %d", c); break; case '%': c = a % b; printf("quotient of two numbers is %d", c); break; default: printf("Invalid operator"); break; } getch(); }
Output
Enter you operator(+, -, /, *, %) + Enter the values of a and b 1 3 addition of two numbers is 4
No comments:
Post a Comment