Kamis, 27 Maret 2014

Ebook Chapter 5 Problem Solving and Program Design in C


  • 5.4 Figure 5.7 Function to Compute Factorial
#include <cstdlib>
#include <iostream>

using namespace std;

int faktorial(int n) {
    int i, product=1;
   
    for (i=n; i>1; --i) {
        product=product*i;
}      
    return product;

}
int main(int argc, char *argv[])
{
    int n;
    cout<<"Masukkan nilai= ";
    cin>> n ;
    cout<< faktorial(n) ;
   
    system("PAUSE");
    return EXIT_SUCCESS;
}



RUN :

0 komentar:

Posting Komentar

 

Anita © 2010

Blogger Templates by Splashy Templates