Advertisement
Malware_N

Calc

Feb 25th, 2021
621
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.87 KB | None | 0 0
  1. #include<stdio.h>
  2. int main()
  3. {
  4.     int choice;
  5.     float x, y, result;
  6.     printf("1. Addition\n");
  7.     printf("2. Subtraction\n");
  8.     printf("3. Multiplication\n");
  9.     printf("4. Division\n");
  10.     printf("5. Exit\n\n");
  11.     printf("Enter your choice: ");
  12.     scanf("%d", &choice);
  13.  
  14.     if (choice >= 1 && choice <= 4)
  15.     {
  16.         printf("Enter any two numbers: ");
  17.         scanf("%lf %lf", &x &y);
  18.     }
  19.     switch(choice)
  20.     {
  21.     case 1:
  22.         result = x+y;
  23.         printf("Result = %0.2f", result);
  24.         break;
  25.     case 2:
  26.         result = x-y;
  27.         printf("Result = %0.2f", result);
  28.         break;
  29.     case 3:
  30.         result = x*y;
  31.         printf("Result = %0.2f", result);
  32.         break;
  33.     case 4:
  34.         result = x%y;
  35.         printf("Result = %0.2f", result);
  36.         break;
  37.     case 5:
  38.         return 0;
  39.     }
  40.     return 0;
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement