Created
September 22, 2011 13:11
-
-
Save adolfont/1234724 to your computer and use it in GitHub Desktop.
Variação do programa do slide 5
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
//Exemplo: Calcular o fatorial de um número n(sem função): | |
// Autor: João Fabro | |
// Modificações: Adolfo Neto | |
#include <stdio.h> | |
#include <stdlib.h> | |
long i,n,fatorial; | |
int main() | |
{ | |
printf("Digite o número N:"); | |
scanf("%d", &n); | |
if (n>31){ | |
printf("Erro! Não dá para calcular o fatorial de um número superior a 31 com long nesta máquina.\n"); | |
return -1; | |
} | |
fatorial = 1; | |
for(i=2;i<=n;i++) | |
{ | |
fatorial = fatorial * i; | |
} | |
if(n>=0) | |
{printf("O fatorial de N = %d vale %d.\n", n, fatorial);} | |
else | |
{printf("Não existe fatorial de numero negativo\n");} | |
// system("PAUSE"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment