Kamis, 30 Juni 2011

Factorial

On this occasion I will try to create a program to find factorial. before I will explain the meaning of the factorial. Factorial is the result of the multiplication of positive integers from 1 to n is called n factorial is written n!
so n! = 1.2.3 .... ... .. (N-2) (n-1). N, and 0! = 1

This is the sourcecode:
#include <iostream.h>
#include <math.h>
#include <conio.h>

int faktorial(int a);
main()
{
    int n;
   clrscr();
   cout << "Masukkan bilangan : ";
   cin >> n;
   cout << "Faktorial" << n <<" = " << faktorial(n);
   getch();
}
int faktorial (int a)
{ int hasil;
    if(a<=1)
   {hasil=1; }
   else
   { hasil=a*faktorial(a-1); }
   return(hasil);
}

This is the view after the writing on the Borland C++:


0 komentar:

Posting Komentar