2023-01-25
Max. 20 points
Name:
Task | Max. | Achieved |
---|---|---|
1 | 10 | |
2 | 10 | |
Sum | 20 |
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)
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");}
}
}
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)
max(int a, int b)
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))));
}