Advertisement
shawonrog

Simple Calculator

Sep 22nd, 2019
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.04 KB | None | 0 0
  1. int main()
  2. {
  3.  
  4.     int input,a,b,result;
  5.     char x;
  6.  
  7. do{
  8.  
  9.     printf("Calculator:\n");
  10.  
  11.     printf("\nEnter 1 for Addition:\n ");
  12.     printf("Enter 2 for Subtraction:\n ");
  13.     printf("Enter 3 for Multiplication:\n ");
  14.     printf("Enter 4 for Division:\n ");
  15.  
  16.     scanf("%d",&input);
  17.     printf("Enter number 01:\n");
  18.     scanf("%d",&a);
  19.     printf("Enter number 02:\n");
  20.     scanf("%d",&b);
  21.  
  22.     switch(x){
  23.         case 1 : result=a+b;
  24.                  printf("The addition is : %d\n",result);
  25.                  break;
  26.         case 2 : result=a-b;
  27.                  printf("The Substraction is : %d\n",result);
  28.                  break;
  29.         case 3 : result=a*b;
  30.                  printf("The Multiplication is : %d\n",result);
  31.                  break;
  32.         case 4 : result=a/b;
  33.                  printf("The division is : %d\n",result);
  34.                  break;
  35.  
  36.         default: printf("wrong input\n");
  37.  
  38.     }
  39.     printf("Do you want to continue ? (y/n)\n");
  40.     option=getche();
  41.  
  42.     }while(option=='y');
  43.  
  44.  return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement