Menentukan Bilangan Faktorial dengan metode Rekursif

Flowchart

fakt1 fakt2

Coding C++

#include <iostream>
#include <string>

using namespace std;
class faktorial{
public:
faktorial();
void input();
void parameter();
private:
int n, a=1;
};

void faktorial::input(){

cout << “Masukan Nilai N! : “;
cin >> n;
}

void faktorial::parameter(){

if (n==0){
cout << “rekursif dari N! : “<< a << endl; }
elseĀ {
a=n*a;
n=n-1;
parameter();
}
}

faktorial::faktorial(){
cout << “tegar putra kurniawan \n1400018036 \n” << endl;
}

int main()
{
faktorial f;
f.input();
f.parameter();
return 0;
}

faktc++1 faktc++2

Advertisements

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