Pages

100 Contemporary Living Room Designs

Saturday, December 8, 2012

C++ PROGRAM - FACTORIAL USING RECURSION.

Write a C++ program which calculates the factorial of a given number using recursion.

#include<conio.h>
#include<iostream.h>
long factorial (long a)
{
    if (a > 1)
        return (a * factorial (a-1));
    else
        return (1);
}
int main ()
{
    long ln;
    clrscr();
    cout << "Enter a number: ";
    cin >> ln;
    cout << ln << "!" << " = " << factorial (ln);
    getch();
    return 0;
}


OUTPUT








You might also like:-

10 comments:


  1. Very Informative and creative contents. This concept is a good way to enhance the knowledge. thanks for sharing.
    Continue to share your knowledge through articles like these, and keep posting more blogs.
    And more Information Data Labeling Service for Machine Learning

    ReplyDelete
  2. BIIT Technology in Laxmi Nagar is renowned for offering best computer classes in Laxmi Nagar with guaranteed placement assistance.

    ReplyDelete
  3. BIIT Technology in Laxmi Nagar is renowned for offering best computer classes in Laxmi Nagar with guaranteed placement assistance.

    ReplyDelete