All pastes #210056 Raw Edit

Stuff

public text v1 · immutable
#210056 ·published 2006-10-19 14:16 UTC
rendered paste body
### rekursiv
def fakultaet_rek(n)
  if n > 0
    return n * fakultaet_rek(n - 1)
  else
    return 1
  end
end


### iterativ
def fakultaet_it(n)
  t = 1
  for i in 1..n
    t = t * i
  end
  return t
end


### Zahl-Eingabe
print "Zahl: "
zahl = gets.to_i

print "REK:  "
puts fakultaet_rek(zahl)

print "IT:   "
puts fakultaet_it(zahl)


#######################################
### Hasenpopulation
def hasenpop(n)
  if n < 2
    return 1
  else
    return hasenpop(n - 1) + hasenpop(n - 2)
  end
end

puts hasenpop(zahl)