Advertisement
satriafu5710

Nilai Faktorial c++

Dec 8th, 2020
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.51 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. int faktorial(int n){
  5.     if(n <= 1){
  6.        
  7.         cout<< n;
  8.         return n;
  9.     }
  10.     else{
  11.        
  12.         cout<<""<< n << " x ";
  13.         return n * faktorial(n - 1);
  14.     }
  15. }
  16.  
  17. int main(){
  18.     int angka, hasil;
  19.    
  20.     cout<<"\t Mencari Nilai Faktorial Dari Suatu Bilangan \n\n";
  21.     cout<<"\n Masukkan Bilangan  : ";cin>>angka;
  22.     cout<<endl;
  23.    
  24.     hasil = faktorial(angka);
  25.     cout<<endl;
  26.     cout<<"\n Nilai Faktorialnya : "<< hasil <<endl;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement