Exercise 5 draft

Added Exercise 5 but incomplete
This commit is contained in:
2025-03-21 23:35:38 +01:00
parent d1c3fcd614
commit 4655cd3477
4 changed files with 226 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
// PRE: x > 0
// POST: returns n^x
int f1(int n, int x) {
int res = 1;
for (; x > 0; x--) {
res *= n;
}
return res;
}
// PRE: n > 0
// POST: returns number of devisions by 10 with n
int f2(int n) {
int i = 0;
while (n > 0) {
n = n / 10;
++i;
}
return i;
}
// PRE: n > 1
// POST: returns a bool to determine if n is prime
bool f3(int n) {
int i = 2;
for (; n % i != 0; ++i);
return n == i;
}
// PRE: n is square number
// POST: returns root of n
int f4(int n) {
int i = 0;
while (i * i != n) {
++i;
}
return i;
}