1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| program expo
implicit none
integer n,p, combi
integer, external :: comb
print * ,'entrer le nombre n:'
read *,n
print * ,'entrer le nombre p'
read *,p
COMBI=comb(n,p)
print *, COMBI
end program expo
integer function fact(m) !pour le kind, je te conseil le max que ton compilo supporte
implicit none
integer,intent(in) :: m !pour etre sûr de pas le modifié dans la fonction
integer i;
fact=1
do i=2,m !pas besoin de commencer à 1, à causs de la ligne precedente
fact=fact*i
end do
return !trèèèèèèèès important, faut retourné la valeur de fact!!!!
end function fact
integer function comb(n,p)
implicit none
integer,intent(in) :: n,p
integer, external :: fact
comb=fact(n)/(fact(p)*fact(n-p))
return
end function comb |
Partager