quarta-feira, 16 de junho de 2010

Java e Fatoriais

Estudando nºs Fatoriais (n!) p/ matemática , resolvi fazer um codigo java p/ analisar melhor :


/*
  Professor :   
  Version 1.0 
Created by Mario Cezzare mcezzare@gmail.com  on   Wed May 26 21:36:53 on ttys000
Faculdade Veris IBTA : Turma 1ADSI / 2010
// 
 * Apostila XXX
 * ALG n : 1
 * CAPITULO: 
 * PAGINA :    
 * EXERCICIO : XX
 * 
 * 
EXERCICIO 
/ estudo de math 
 * mostra tabela de fatoriais
 * */ 


 public class  math_fatorial{

public static void main(String arg[]){
    long numero = 2, resposta=1;
    long cont;
  
          while(numero < 20){
                  for(cont = numero; cont > 1; cont--){
                         resposta = resposta * (cont);
                  }
                  System.out.println("Fatorial de "+numero+" é "+resposta);
                  numero ++;
                  resposta = 1;
          }
   }
}


--------resultado deve ser : -------------


Fatorial de 2 é 2
Fatorial de 3 é 6
Fatorial de 4 é 24
Fatorial de 5 é 120
Fatorial de 6 é 720
Fatorial de 7 é 5040
Fatorial de 8 é 40320
Fatorial de 9 é 362880
Fatorial de 10 é 3628800
Fatorial de 11 é 39916800
Fatorial de 12 é 479001600
Fatorial de 13 é 6227020800
Fatorial de 14 é 87178291200
Fatorial de 15 é 1307674368000
Fatorial de 16 é 20922789888000
Fatorial de 17 é 355687428096000
Fatorial de 18 é 6402373705728000
Fatorial de 19 é 121645100408832000

Nenhum comentário: