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:-
#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:-
This post is so helpfull and informative.Keep updating with more information...
ReplyDeleteCyber Security Course in Mumbai
Cyber Security Course in Ahmedabad
Cyber Security Course in Kochi
Cyber Security Course in Trivandrum
Cyber Security Course in Kolkata
ReplyDeleteVery 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
Thanks for sharing information abotu C++Private Tutor Gilbert
ReplyDeleteNow i know much about C++ program Special Needs Tutor Scottsdale
ReplyDeleteIts good to know about this program Private Tutor Greater Heights
ReplyDeleteAmazing guidance Private Tutor Chandler
ReplyDeleteThis article is good about C++ program Private tutor Naples
ReplyDeleteWhat a great web blog about C++ . Private tutor Tampa
ReplyDeleteLearning 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