Program to find factorial of -1 to 6 numbers


        #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

 
 
 
 


Copyright © 2012 http://codeprecisely.blogspot.com. All rights reserved |Term of Use and Policies|