1AKIFT POS Test (Group A)

2023-01-25

Max. 20 points

Name:

Task Max. Achieved
1 10
2 10
Sum 20
Grading: >= 18: 1, 15-17: 2, 12-14: 3, 10-11: 4, <10: 5
  1. Implement a function void representation(int low, int high) that prints textual representations of numbers. For each integer num between low (inclusive) and high (non inclusive) a representation must be printed. If 1 <= num <= 9 print the textual representation of the digit ("one" for 1 etc.) on a separate line of output. For numbers larger than 9, print "even" if num is an even number, otherwise "odd". (10 points)
    1 point for correct signature
    2 points for looping over the correct range
    3 points for representing 1-9 correctly
    2 points for even numbers >= 10
    2 points for odd numbers >= 10
    void representation(int low, int high) {
      for (; low < high; ++low) {
        if (low == 1) {printf("one\n");}
        if (low == 2) {printf("two\n");}
        if (low == 3) {printf("three\n");}
        if (low == 4) {printf("four\n");}
        if (low == 5) {printf("five\n");}
        if (low == 6) {printf("six\n");}
        if (low == 7) {printf("seven\n");}
        if (low == 8) {printf("eight\n");}
        if (low == 9) {printf("nine\n");}
        if (low > 9 && low % 2 == 0 ) {printf("even\n");}
        if (low > 9 && low % 2 == 1 ) {printf("odd\n");}
      }
    }
  2. Implement a function
    int max_of_five(int a, int b, int c, int d, int e) in C. The function must return the maximum of the 5 given numbers. To facilitate this, implement a function int max(int a, int b), returning the maximum of its arguments. max_of_five(.) must use max(.) for its calculation. (10 points)
    2 points the correct function names and signatures
    3 points for the correct implementation of max(int a, int b)
    5 Punkte für die richtige Implementierung von max_of_four
    int max(int a, int b) {
        if (a > b) return a;
        return b;
    }
    
    int max_of_five(int a, int b, int c, int d, int e) {
        return max(a, max(b, max(c, max(d, e))));
    }