Created
December 2, 2017 22:24
-
-
Save zrhans/664f676f4b66adf549539ca2b788c6cd to your computer and use it in GitHub Desktop.
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
!Software para calcular o fatorial de nùmeros inteiros | |
!Desenvolvido por Denrlei Machado da Silva em 18/11/2017 | |
!Versão 2017 | |
program fatorial1 | |
implicit none | |
!Declaração das variáveis | |
real :: a, x | |
real :: fatorial | |
!Bloco de texto para capturar o valor do número a ser calculado o fatorial (no caso a variável x) | |
print*, " " | |
print*, " " | |
print*, "========================================" | |
print*, "****Utilize somente numeros inteiros****" | |
print*, " " | |
print*, " " | |
print*, " Encontrar o valor fatorial do numero:" | |
print*, "----------------------------------------" | |
print*, " " | |
read *, x | |
!Cálculo fatorial da variável x | |
a = fatorial(x) | |
!Se o valor de x for maior que 31 não é para efetuar o cálculo | |
if (x > 34) then | |
print*, "====================================" | |
print*, " Excede valor Maximo Permitido " | |
print*, " " | |
print*, " " | |
print*, "**OBS - Valor Maximo Permitido = 34**" | |
print*, "====================================" | |
print*, " " | |
goto 42 | |
endif | |
print *,x,"! = ", a | |
42 continue | |
end program fatorial1 | |
!Utilizando o subprograma recursivo | |
recursive function fatorial(n) result (fac) | |
implicit none | |
!Declaração das variáveis | |
real :: n, fac | |
!Se 0 for o valor a ser calculado o fatorial, a resposta será 1 | |
if (n == 0) then | |
fac = 1 | |
!Se não for | |
else | |
fac = n * fatorial(n - 1) | |
endif | |
end function fatorial |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment