Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.42 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include <string.h>
  5.  
  6. int addition(int a, int b);
  7. int subtraction(int a, int b);
  8. int multiplication(int a, int b);
  9. int division(int a, int b);
  10. int modulo(int a, int b);
  11.  
  12. int main(void) {
  13.    
  14.     char selection;
  15.    
  16.     int a, b, c;
  17.    
  18.     printf("Please select one of the following operations: \n"
  19.            "a - addition\n"
  20.            "s - subtraction\n"
  21.            "m - multiplication\n"
  22.            "d - division\n"
  23.            "r - modulo\n"
  24.            "Char: ");
  25.            
  26.     scanf("%c", &selection);
  27.    
  28.     if(selection == 'a') {
  29.         printf("Enter a number: \n");
  30.         scanf("%d", &a);
  31.        
  32.         printf("Enter another number: \n");
  33.         scanf("%d", &b);
  34.        
  35.         c = addition(a ,b);
  36.        
  37.         printf("%d + %d = %d\n", a, b, c);
  38.     }
  39.    
  40.     else if(selection == 's') {
  41.         printf("Enter a number: \n");
  42.         scanf("%d", &a);
  43.        
  44.         printf("Enter another number: \n");
  45.         scanf("%d", &b);
  46.        
  47.         c = subtraction(a ,b);
  48.        
  49.         printf("%d - %d = %d\n", a, b, c);
  50.     }
  51.    
  52.     else if(selection == 'm') {
  53.         printf("Enter a number: \n");
  54.         scanf("%d", &a);
  55.        
  56.         printf("Enter another number: \n");
  57.         scanf("%d", &b);
  58.        
  59.         c = multiplication(a ,b);
  60.        
  61.         printf("%d * %d = %d\n", a, b, c);
  62.     }
  63.    
  64.     else if(selection == 'd') {
  65.         printf("Enter a number: \n");
  66.         scanf("%d", &a);
  67.        
  68.         printf("Enter another number: \n");
  69.         scanf("%d", &b);
  70.        
  71.         c = division(a ,b);
  72.        
  73.         printf("%d / %d = %d\n", a, b, c);
  74.     }
  75.    
  76.     else if(selection == 'r') {
  77.         printf("Enter a number: \n");
  78.         scanf("%d", &a);
  79.        
  80.         printf("Enter another number: \n");
  81.         scanf("%d", &b);
  82.        
  83.         c = modulo(a ,b);
  84.        
  85.         printf("%d r %d = %d\n", a, b, c);
  86.     }
  87.    
  88.     else {
  89.         printf("Wrong choice! Re-run program.\n");
  90.     }
  91.    
  92. }
  93.  
  94. int addition(int a, int b) {
  95.     int ans = a + b;
  96.     return ans;
  97. }
  98.  
  99. int subtraction(int a, int b) {
  100.     int ans = a - b;
  101.     return ans;
  102. }
  103.  
  104. int multiplication(int a, int b) {
  105.     int ans = a * b;
  106.     return ans;
  107. }
  108.  
  109. int division(int a, int b) {
  110.     int ans = a / b;
  111.     return ans;
  112. }
  113.  
  114. int modulo(int a, int b) {
  115.     int ans = a % b;
  116.     return ans;
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement