#include <iostream.h>
#include <conio.h>
long factorial (int i); //Declaration (Prototype)
void main( )
{
for( int i = -1 ; i < 7; i++)
cout<<"fact ( " << i << " ) = "<<fact(i)<<endl;
getch( );
}
long factorial ( int n)
{
if (n < 2) return 1;
long f = 1;
for ( int i = 2; i < = n ; i++)
f * = i ;
return (f );
}
0 comments:
Post a Comment