fork download
  1. // program for switch statement
  2. // making a calculator
  3. #include <stdio.h>
  4. int main(){
  5. int a,b ;
  6. char choise;
  7. printf("Enter the two numbers:\n");
  8. scanf("%d %d" ,&a,&b);
  9. printf("Choose Operation:\n For add(+):\nFor Sub(-):\nFor Mult(*)\nFor Div(/)\n");
  10. scanf("%c",&choise);
  11. switch(choise){
  12. case '+':
  13. printf("a+b=%d\n",(a+b));
  14.  
  15. case '-':
  16. printf("a-b=%d\n",(a-b));
  17.  
  18. case '*':
  19. printf("a*b=%d\n",(a*b));
  20.  
  21. case '/':
  22. printf("a/b=%d\n",(a/b));
  23.  
  24. default:
  25. printf("It's Error! \nEnter again");
  26. }
  27. return 0;
  28. }
Success #stdin #stdout 0.01s 5276KB
stdin
Standard input is empty
stdout
Enter the two numbers:
Choose Operation:
 For add(+):
For Sub(-):
For Mult(*)
For Div(/)
It's Error! 
Enter again