Write a program to Make a Simple Calculator Using switch-case or Design calculator using switch case.
C Program
#include <stdio.h>int main(){int firstNum, secondNum;char operator;printf("Enter any operator (+,-,*,/): ");scanf("%c", &operator);printf("Enter first number : ");scanf("%d", &firstNum);printf("Enter second number : ");scanf("%d", &secondNum);switch (operator){case '+':printf("%d + %d is %d", firstNum, secondNum, firstNum + secondNum);break;case '-':printf("%d - %d is %d ", firstNum, secondNum, firstNum - secondNum);break;case '*':printf("%d * %d is %d ", firstNum, secondNum, firstNum * secondNum);break;case '/':printf("%d / %d is %f", firstNum, secondNum, (float)firstNum / secondNum);break;default:printf("Operator is not valid");break;}}
Example:
Enter any operator (+,-,*,/): +
Enter first number : 12
Enter second number : 34
Example:
12 + 34 is 46
No comments:
Post a Comment