Sabtu, 02 April 2016

Kasus 5.5 Factorial

Algoritma:
  • Memasukkan nilai faktorial yang bertipe data integer.
  • Proses memfaktorkan nilai yang dimasukkan.
  • Mengoutputkan hasil faktorial.

 *DevC++

#include <iostream>
#include <cstdlib>
#include <string>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

using namespace std;

void faktor (int n, int x, int hasil){
    if (x>n){
        cout<<"faktor "<<n<<" adalah "<<hasil<<endl;
        }
    else{
        hasil = hasil*x;
        x=x+1;
        faktor (n,x,hasil);   
    }
}
   
int main(int argc, char** argv) {
    int hasil, n, x;
   
    cout<<"Masukkan Nilai faktorialnya : ";  cin>>n;
    cout<<endl;
   
    x=1;
    hasil=1;
    faktor(n,x,hasil);
   
    return 0;
}



*Raptor




Share:

0 komentar:

Posting Komentar