Analysis Program :

The program is to find out the results of factorial. The factorial of a non-negative integer n, denoted by n!, is the product of all positive integers less than or equal to n. For example, 4!=4*3*2*1

The result is 24. Program uses function for(int i=1; i<=n; i++).

Algorithm:

1. Input (n)

2. Conditions of this program adalan (n> 0)

3. for (int i = 1; i <= n; i + +) factor *= i
4. Output

Program :

[sourcecode language="css"]
#include <iostream.h>
#include <conio.h>
class faktorial{
public:
int proses()
void keluaran();
private:
int n,faktor;
};
int faktorial::proses()
{ cout<<"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 terhitung";
}
return faktor;
}
void faktorial::keluaran()
{
cout<<end<<endl<<"faktorial dari "<<n<<"! = "<<faktor;
}
int main()
{
faktorial bilangan;
bilangan.proses();
bilangan.keluaran();
getch();
return 0;
}
[/sourcecode]