zaman360live

Calculator in C Program If Else

Apr 20th, 2021 (edited)
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.37 KB | None | 0 0
  1. /* In The Name Of Allah
  2. Student ID is 211-15-4031*/
  3.  
  4. #include <stdio.h>
  5. int main()
  6. {
  7.     for (; ;)
  8.     {
  9.    
  10.    int num1, num2, choice; //decleration of integer variables
  11.               //decleration of character variables
  12.     printf("\n\n\npress 1 for Addition \n");
  13.     printf("\npress 2 for Substraction \n");
  14.     printf("\npress 3 for Multiplicetion \n");
  15.     printf("\npress 4 for Division \n");
  16.     printf("\npress 0 for Exit\n\n \n");
  17.     scanf("%d", &choice);
  18.     if (choice == 0)
  19.         break;
  20.    
  21.    else if (choice == 1)
  22.     {
  23.         printf("\n\nEnter Two Integer Number \n");
  24.         scanf("%d %d", &num1, &num2);
  25.         printf("The result of substraction is: %d",num1+num2);
  26.     }
  27.    else if (choice == 2)
  28.     {
  29.         printf("\n\nEnter Two Integer Number \n");
  30.         scanf("%d %d", &num1, &num2);
  31.         printf("The result of Addition is: %d", num1 - num2);
  32.     }
  33.    else if (choice == 3)
  34.     {
  35.         printf("\n\nEnter Two Integer Number \n");
  36.         scanf("%d %d", &num1, &num2);
  37.         printf("The result of Multiplication is: %d", num1 * num2);
  38.     }
  39.    else if (choice == 4)
  40.     {
  41.         printf("\n\nEnter Two Integer Number \n");
  42.         scanf("%d %d", &num1, &num2);
  43.         printf("The result of Division is: %d", num1 / num2);
  44.     }
  45.  
  46.     else
  47.         printf("\nWrong Input\nPleasen Try Again\n" );
  48.     }
  49.     return 0 ;
  50. }
Add Comment
Please, Sign In to add comment