Quantcast
Channel: Programação - GUJ
Viewing all articles
Browse latest Browse all 33093

Fatorial de 1 até N

$
0
0

@Raizde2 escreveu:

Eu tenho este programa para calcular o fatorial de um número entrar 1 e 10. A minha próxima tarefa/exercício é fazer um programa que calcule o fatorial de 1 até N, inserido pelo utilizador. Podem ajudar?

import java.util.*;
public class fatorial {
    
    public static void main (String args[]) {
    Scanner aa = new Scanner(System.in);
    int n, fator=1;
    
    System.out.print("Insira um número entre 1 e 10: ");
    n=aa.nextInt();
    
    for (int x=1; x<=n; x++) {
        fator *= x; }
        System.out.printf("%2d!=%2d", n, fator); 
    }
}

Mensagens: 2

Participantes: 2

Ler tópico completo


Viewing all articles
Browse latest Browse all 33093


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>