Add factorielle
This commit is contained in:
parent
13970cb831
commit
f2317e69ca
2 changed files with 31 additions and 0 deletions
13
algorithmique/recursivite/factorielle.algo
Normal file
13
algorithmique/recursivite/factorielle.algo
Normal file
|
@ -0,0 +1,13 @@
|
|||
Algorithme : Calcule la factorielle d'un entier N positif
|
||||
|
||||
Début
|
||||
|
||||
Fonction Factorielle(N : int)
|
||||
Si N = 1
|
||||
Retourner(1)
|
||||
Sinon
|
||||
Retourner(N * Factorielle(N - 1))
|
||||
FinSi
|
||||
FinFonction
|
||||
|
||||
Fin
|
18
algorithmique/recursivite/factorielle.py
Normal file
18
algorithmique/recursivite/factorielle.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
"""Algorithme : Calcule la factorielle d'un entier N positif"""
|
||||
|
||||
|
||||
def main() -> None:
|
||||
print(Factorielle(5))
|
||||
|
||||
|
||||
def Factorielle(N : int) -> int:
|
||||
if N == 1:
|
||||
return 1
|
||||
else:
|
||||
return N * Factorielle(N - 1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Loading…
Reference in a new issue