aufgabe 5 angefangen aber noch fehlerhaft bei triangles(sum())
This commit is contained in:
parent
8a7956ac4a
commit
f0ab9867bf
@ -59,3 +59,27 @@ def binKoeffRek(m:Int,n:Int):Int = {
|
||||
else return m * binKoeffRek(m - 1, n - 1) / n
|
||||
}
|
||||
|
||||
|
||||
//Aufgabe 5
|
||||
|
||||
def triagnles(n:Int):Int = {
|
||||
|
||||
// mistake is in sum it always returns 1
|
||||
|
||||
def sum(i: Int, n: Int): Int = {
|
||||
if (i <= n) then{
|
||||
// println("Test1")
|
||||
return (n-i)+sum(i+2,n)
|
||||
}
|
||||
else {
|
||||
1
|
||||
}
|
||||
}
|
||||
// println("Test2")
|
||||
if (n == 1) {
|
||||
return 1
|
||||
} else {
|
||||
//return n
|
||||
return triagnles(n - 1) + ((n * (n + 1)) / 2) + sum(1,n)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user