a glimpse of the factorial :
Here we let (n) as the number who would we look for value faktorialnya.
In mathematics the factorial of a bialngan formulated by:
n! = n * (n-1) ... ... * 1
or
n! = 1 * (n 1) ... ..* n
ALGORITHM calculate the factorial :
1.Tentukan fariabel i, n, factorial
2.faktorial = 1;
3.scanf (n)
4.for (i = 1; i <= n; i) {factorial = factorial * i;}
5.printf (factorial);
6.End.
The following java program :
import jeliot.io.*;
public class faktorial
{
public static void main (String[ ] args)
{
long limit = 20; // menghitung faktorial integer daeri 1 – 20
long faktorial = 1; // pendefinisian variabel faktorial
for (int i = 0; i <= limit; i++)
{
faktorial = 1;
for (int faktor = 2; faktor <= i; faktor ++)
faktorial *= faktor;
System.out.println (i + "!" + " adalah " + faktorial);
}
}
}
Tidak ada komentar:
Posting Komentar