Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Dado um número natural diferente de 0, o loop fatora cada número em
- * sequência e imprime o resultado no prompt.
- * Equação: n! = n * (n - 1) * (n - 2) * ...
- *
- */
- class Main {
- public static void main (String[] args) {
- int x;
- long f, last;
- last = 0;
- for (int i = 0; i <= 10; ++i) {
- x = i; f = i;
- if (x == 0 || x == 1) {
- System.out.println("1");
- } else {
- while (x > 1) {
- f *= (x - 1);
- if (f == last)
- break;
- else
- System.out.println(f);
- last = f;
- --x;
- }
- }
- System.out.println("---");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement