-Black Inspiration- -Telor-ceplox- -PROFIL- -Facebook- -Twitter- "* ikhsan_choco@ymail.com "*
Stop Dreaming and Start Action Now...!!----Stop Dreaming and Start Action Now...!!----Stop Dreaming and Start Action Now...!!----Stop Dreaming and Start Action Now...!!----Stop Dreaming and Start Action Now...!!----Stop Dreaming and Start Action Now...!!----Stop Dreaming and Start Action Now...!!----Stop Dreaming and Start Action Now...!!----Stop Dreaming and Start Action Now...!!----Stop Dreaming and Start Action Now...!!----Stop Dreaming and Start Action Now...!!----Stop Dreaming and Start Action Now...!!----Stop Dreaming and Start Action Now...!!----Stop Dreaming and Start Action Now...!!----Stop Dreaming and Start Action Now...!!----Stop Dreaming and Start Action Now...!!----Stop Dreaming and Start Action Now...!!----Stop Dreaming and Start Action Now...!!----Stop Dreaming and Start Action Now...!!----Stop Dreaming and Start Action Now...!!----Stop Dreaming and Start Action Now...!!----Stop Dreaming and Start Action Now...!!----Stop Dreaming and Start Action Now...!!----Stop Dreaming and Start Action Now...!!----Stop Dreaming and Start Action Now...!!----Stop Dreaming and Start Action Now...!! Jangan lupa kasih komentar demi kemajuan blog ini...!!!

3 Apr 2011

Java program to calculate the factorial (menghitung nilai faktorial dg java)

 Award as the value of factorial is the result of the multiplication of positive integers less than or equal to the value N. Writing is usually a factorial: n!

Now we will create a program to calculate factorial. A factorial in difinisikan as follows:

n!=n x(n-1)x(n-2)x......x 2 x 1


examples
:

2!= 2 x 1 =2
3!= 3 x 2 x 1 =6
4!= 4 x 3 x 2 x 1 = 24

Algoritma:

1. Masukkan (n)
2. bil <-- n
2. hasil=1
3.untuk bil>=1, maka bil-1
hasil <-- hasil* bil
4. tampilkan(hasil)

The following 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