RSieve

Script prova ideone in C

Feb 6th, 2020
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.29 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. enum boolean {True = 1, False = 0};
  4.  
  5. int sum (int, int);
  6. int difference (int, int);
  7. int multiplication (int, int);
  8.  
  9. int main(void) {
  10.    
  11.     int op, num1, num2;
  12.    
  13.     printf ("Choose your operation\n");
  14.     printf ("1. Sum\n");
  15.     printf ("2. Number distance (always positive)\n");
  16.     printf ("3. Multiplication\n");
  17.    
  18.     scanf("%d", &op);
  19.    
  20.     printf("Insert first number: ");
  21.     scanf("%d", &num1);
  22.     printf("\n");
  23.    
  24.     printf("Insert second number: ");
  25.     scanf("%d", &num2);
  26.     printf("\n");
  27.    
  28.     switch(op) {
  29.         case 1:
  30.             printf("The sum of %d and %d is: %d", num1, num2, sum(num1, num2));
  31.             break;
  32.         case 2:
  33.             printf("The distance between %d and %d is: %d", num1, num2, difference(num1, num2));
  34.             break;
  35.         case 3:
  36.             printf("The multiplication of %d and %d is: %d", num1, num2, multiplication(num1, num2));
  37.             break;
  38.     }
  39.    
  40.     // your code goes here
  41.     return 0;
  42. }
  43.  
  44. int sum (int num1, int num2) {
  45.     return num1 + num2;
  46. }
  47.  
  48. enum boolean is_bigger (int num1, int num2) {
  49.     return num1 > num2;
  50. }
  51.  
  52. int difference (int num1, int num2) {
  53.     if (is_bigger(num1, num2)) {
  54.         return num1 - num2;
  55.     } else {
  56.         return num2 - num1;
  57.     }
  58. }
  59.  
  60. int multiplication (int num1, int num2) {
  61.     if (num2 == 0) {
  62.         return num1;
  63.     } else {
  64.         return multiplication (num1 + num1, num2 - 1);
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment