Minggu, 02 Oktober 2011

2

[C/C++] Program Penghitung Faktorial

  • Minggu, 02 Oktober 2011
  • Nurkholish Ardi Firdaus
  • Share
  • Kali ini saya iseng membuat program penghitung faktorial menggunakan C++. Tujuan dari keisengan saya ini adalah saya ingin tahu apakah C++ mendukung metode panggilan fungsi secara rekursif. Eh ternyata bisa... Mari kita tenggok source code nya..










    #include <iostream>
    
    using namespace std;
    
    double fact(double n);
    
    int main()
    {
        int n;
        cout << "###################################n";
        cout << "### UNIVERSITAS NEGERI SEMARANG ###n";
        cout << "###       Factorial Solver      ###n";
        cout << "###   Nurkholish Ardi Firdaus   ###n";
        cout << "###################################n";
    
        cout << "Masukkan angka: ";
        cin >>  n;
        cout << "n";
        cout << n << "!=";
        cout << fact(n) << endl;
        return 0;
    }
    
    double fact(double n)
    {
        if (n>1) return n*fact(n-1);
        else return 1;
    }
    Jangan Lupa Komentar Yaa..
    Related Posts Plugin for WordPress, Blogger...

    2 Komentar Untuk “[C/C++] Program Penghitung Faktorial”

    angga-fian mengatakan...
    Jumat, 01 Juni 2012 pukul 21.41.00 WIB Reply To This Comment

    mas cara psang coding di blog untuk text kyk punya mas itu gimana ya ?? yang warna black itu ..€€


    Blogger mengatakan...
    Kamis, 27 Februari 2020 pukul 04.52.00 WIB Reply To This Comment

    Use this diet hack to drop 2 lb of fat in just 8 hours

    More than 160,000 women and men are utilizing a easy and SECRET "liquid hack" to lose 1-2 lbs each and every night while they sleep.

    It's effective and it works every time.

    Just follow these easy step:

    1) Get a drinking glass and fill it up with water half glass

    2) Now follow this weight losing HACK

    and become 1-2 lbs skinnier the very next day!


    Posting Komentar

    Berikan komentar positif tentang artikel yang sederhana ini niscaya sobat akan mendapatkan balasannya. Hehehe

    Subscribe