Mencari Nilai Faktorial suatu Bilangan

Factorial value is different from the factors that we know, the value in question is n! Factorial, so for example n is 4 then the value faktorialnnya is 4x3x2x1 = 24.

Algoritma Faktorial

{Mencari nilai factorial dari suatu bilangan n}

Deklarasi

n          : integer {input}

factor : integer {untuk mencari faktorialnya}

Deskripsi

Read n

if(n>0)

for(int i=1; i<=n; i++)

faktor*=i

else if(n=0)

faktor=1

Write n

program C++

#include <iostream.h>

#include <conio.h>

class faktorial {

public:

int proses();

void keluaran();

private:

int n,faktor;

};

int faktorial::proses()

{

cout<<"masukan angka yg akan di faktorialkan : ";

cin>>n;

faktor=1;

if(n>0)

{

for(int i=1; i<=n; i++)

{

faktor*=i;

}

}

else if(n=0)

{

faktor=1;

}

else

{

cout<<"tidak ada";

}

return faktor;

}

void faktorial::keluaran()

{

cout<<endl<<endl<<"faktorial dari "<<n<<"! = "<<faktor;

}

int main()

{

faktorial bilangan;

bilangan.proses();

bilangan.keluaran();

getch();

}
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: