Tamil Nadu Board of Secondary EducationHSC Science Class 11th

Write a program to find the factorial of the given number using recursion. - Computer Science

Advertisement Remove all ads
Advertisement Remove all ads
Advertisement Remove all ads
Answer in Brief

Write a program to find the factorial of the given number using recursion.

Advertisement Remove all ads

Solution

#include<iostream>
using namespace std;
int factorial(int); // Function prototype //
int main()
{
int no;
cout<<"\nEnter a number to find its factorial: ";
cin >> no;
cout << "\nFactorial of Number " << no <<" = " << factorial(no);
return 0;
}
int factorial(int m)
{
if (m > 1)
{
return m*factorial(m-1);
}
else
{
return 1;
}
}

Output :

Enter a number to find its factorial: 5

Factorial of Number 5 = 120

Concept: Recursive Function
  Is there an error in this question or solution?
Chapter 11: Functions - Evaluation - Section - D [Page 205]

APPEARS IN

Tamil Nadu Board Samacheer Kalvi Class 11th Computer Science Answers Guide
Chapter 11 Functions
Evaluation - Section - D | Q 2. | Page 205
Share
Notifications

View all notifications


      Forgot password?
View in app×