- 5.4 Figure 5.7 Function to Compute Factorial
#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