Thursday, April 7, 2016

kasus 5.5

Assalamuallaikum wr. wb.

    Program menghitung bilangan ber faktorial.


1. RAPTOR


2. C++


#include <iostream>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
void factorial(int n, int x, int hasil){
if(x>n)
{
cout<<"faktorial "<<n<<" adalah "<<hasil<<endl;}
else
{
hasil=hasil*x;
x=x+1;
factorial(n,x,hasil);
}
}
int main(int argc, char** argv) {
int hasil;
int n;
int x;
cout<<"Masukkan nilai factorial :";
cin>>n;
x=1;
hasil=1;
factorial( n, x, hasil);
return 0;

}

Dan untuk hasil compilenya adalah :



Semoga bermanfaat !
Terima Kasih


Wassalamuallaikum wr. wb.

0 comments :

Post a Comment