This is source is to find faktorial value, it used a procedural and function.
/*
Name: Faktorial Programm
Copyright: http://tutorialcoding.blogspot.com
Author: Rifki Yandhi
Date: 18/10/09 21:13
Description:
*/
#include <iostream>
#include <conio.h>
using namespace std;
//This is how function is work
int faktorial ( int n )
{
long a = 1;
for ( int i = 1 ; i <= n ; i++ )
{
a = a * i;
}
return a;
}
int main()
{
int n, a = 1;
//input value n from 1 to 15
do
{
cout<<"n! = ";
cin >> n;
}while(n <= 1 && n >= 15 );
//This is how manual way
for ( int i = 1 ; i <= n ; i++ )
{
a = a * i;
}
cout <<"\nManual : "<< n <<"! = "<< a << endl; // this is value from manual way
cout <<"Function : "<< n <<"! = "<< faktorial(n) <<endl; // faktorial(n) is a function that we call from above
getch();
}
Free source code and program download
0 comments:
Post a Comment