Jumat, 08 April 2016

5.5 factorial

  • menghitung factorial rekursif
  • cpp
    #include <iostream>
    using namespace std;

    /* run this program using the console pauser or add your own getch, system("pause") or input loop */
    int fac(int n){
        if(n>1) return fac(n-1)*n;
        else return 1;
    }
    int main(int argc, char** argv) {
        int a;cout<<"factorial : ";cin>>a;
        cout<<fac(a);
        return 0;
    }

Tidak ada komentar:

Posting Komentar