Exercise 5 draft
Added Exercise 5 but incomplete
This commit is contained in:
35
Informatik_I/Exercise_5/Task_3/main.md
Normal file
35
Informatik_I/Exercise_5/Task_3/main.md
Normal file
@@ -0,0 +1,35 @@
|
||||
Please write your solution here.
|
||||
For your convenience we have added a template for your answers below.
|
||||
|
||||
Note: Remember to also describe the problem of the function.
|
||||
|
||||
# Function `c++|is_even`:
|
||||
|
||||
The problem with this function is that it does not return a bool if the number `i` is uneven.
|
||||
|
||||
```c++
|
||||
// PRE: n/a
|
||||
// POST: returns true if i is even. If not it returns false.
|
||||
bool is_even(int i) {
|
||||
if (i % 2 == 0) return true;
|
||||
else return false;
|
||||
}
|
||||
```
|
||||
|
||||
# Function `c++|invert`:
|
||||
|
||||
The problem with this function is
|
||||
|
||||
```c++
|
||||
// PRE: x is positive or negative but not zero.
|
||||
// POST: returns inverse with respect to multiplication of x.
|
||||
double invert(int x) {
|
||||
// TODO: Fix code below.
|
||||
if (x != 0) {
|
||||
return 1.0 / x;
|
||||
}
|
||||
else
|
||||
std::cout << "0 has no inverse!";
|
||||
}
|
||||
```
|
||||
|
Reference in New Issue
Block a user