I explained that first factorial numbers. Example, say you find number 4 then the process:
4!=4*3*2*1
4!=24
yes, the results of 4! is 24.
I am following the literature of the algorithm in advance;
Algoritma:
declaration:
n,faktor : integer
description:
read n
faktor<--1
for i<--1 to n do
faktor*<--i
write faktor
sourcecode:
[sourcecode]
#include <iostream.h>
#include <conio.h>
class fakt{
public:
masukan();
proses();
private:
int n,faktor;
};
fakt::masukan(){
cout<<"\t\tProgram factorial"<<endl;
cout<<"Masukan yang akan di factorialkan = ";
cin>>n;
}
fakt::proses(){
faktor=1;
for(int i=1;i<=n;i++){
faktor*=i;
}
cout<<"Faktor dari "<<n<<"! = "<<faktor<<endl<<endl;
cout<<"http://yusufruli.wordpress.com";
}
int main(){
fakt x;
x.masukan();
x.proses();
getch();
return 0;
}
[/sourcecode]
0 komentar:
Post a Comment