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:-

9 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. Learning from knowledgeable instructors can make a significant difference. Their ability to explain complex topics and provide real-world examples is invaluable.click here for more information.

    ReplyDelete