Thursday, 22 November 2012

Program Menghitung Factorial

#include <cstdlib>
#include <iostream>

using namespace std;

int factorial(int f){
    int hasil=1;
    for(int i=1;i<=f;i++){
            hasil*=i;
            }
    return hasil;
}

int main(int argc, char *argv[])
{
    int a;
    cout<<"Masukan Bilangan yang akan di factorial-kan : ";
    cin>>a;
    cout<<endl<<a<<"! = "<<factorial(a)<<endl<<endl;
   
    system("PAUSE");
    return EXIT_SUCCESS;
}