Program to find factorial of number using Recursive Function


#include <iostream.h>
#include <conio.h>
int recur (int i);                     //Declaration (Prototype)

void main( )
{
        int a, fact;
        cout<<"\n Enter any Number : " ;
        cin>>a;
        if ( a < 0)
           cout<<"\n Number should be positive !! ";
        else
        {
        fact = recur ( a ) ;
        cout<<"\n Factorial value : " << fact ;
        }
    getch( );
}   
    int recur ( int n)
    {
        if ( n == 1 )
            return (1);
        else
      return (n * recur ( n - 1 ) );
      }

0 comments:

Post a Comment

 
 
 
 


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