Monday, April 1, 2013

C Language Example # 48 Recursive Function Call Example # 02 Find out Factorial Using Recursive Function

C Language Example # 48 Recursive Function Call Example # 02 Find out Factorial Using Recursive Function.

* This program is example of recursive call of function.
* Program will calculate .

//Written by : Latest Technology Guide
//Title : C Language Example #   48 Recursive Function Call Example # 02 Find out Factorial Using Recursive Function.

 
#include <stdio.h>
#include <conio.h>

void main()
{
    clrscr();
    long int ans;
    int n;

    long int fac(int,int,int);

    printf("How Many Elements are there :  ");
    scanf("%d",&n);

    ans=fac(1,1,n);

    printf("Factorial is : %ld",ans);

    getch();

}
long int fac(int no,int fact,int n)
{


    if(no>=n)
        return(no);
    else

        fact = no *  (fac(no+1,fact,n));

    return(fact);

}
Output:



--------------------------------------------------------------------------------
Explanation of C Programming Language Example # 48 Recursive Function Call Example # 02 Find out Factorial Using Recursive Function.

*  Program will call function itself (recursive call) to display factorial of given number.


Note: All programs are developed and tested using Turbo C++ 3.0 under Windows XP. We just want to provide guidelines to the users. If you are using any other Compiler or other operating system they you need to modify this program as per your requirements.

No comments:

Post a Comment