algorithme factorielle

This commit is contained in:
gwen
2017-04-06 16:57:22 +02:00
parent 813a09034a
commit 936de04ce4
3 changed files with 78 additions and 0 deletions

View File

@ -0,0 +1,17 @@
let rec fact = function
|1 -> 1
| n -> n * fact (n-1) ;;
let print_fact n =
Printf.printf "factorielle %i = %i\n" n (fact n)
let main () =
begin
print_fact 5 ;
print_newline () ;
exit 0 ;
end
let _ = main ()

View File

@ -0,0 +1,12 @@
def factorielle(n):
if (n > 1):
r = n*factorielle(n-1)
else:
r = 1
return r
def print_fact(n):
print "factorielle {} = {}\n".format(5, factorielle(5))
if __name__ == '__main__':
print_fact(5)