Created
March 9, 2022 09:20
-
-
Save mrsolarius/512dda2c2f964533636a5fd445d5631e to your computer and use it in GitHub Desktop.
Comment faire un factoriel en erlang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% Spéc | |
% fact/1 renvoie le factoriel de l'argument paser en parametre | |
% le fact(N) est N*(N-1)*...*2*1 N appartient à N | |
% | |
% Exemple : | |
% > fact(3) = 6 | |
% Analyse sur N : 2 cas | |
% N = 0 | |
fact(N)->1; | |
% N /= 0 donc il exist P/N=P+1 | |
%fact(N)-> | |
% P=N-1, | |
% F=fact(P), | |
% N*F. | |
% Ou bien | |
fact(N) when N>0 -> N*fact(N-1). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment