[go: up one dir, main page]

0% found this document useful (0 votes)
50 views1 page

Factorial Using Recursion

The document contains C++ code that demonstrates two methods for calculating the factorial of a number: a recursive method (commented out) and an iterative method. The iterative method prompts the user to enter a number and calculates its factorial using a for loop. The result is then printed to the console.

Uploaded by

Abdul Haq
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views1 page

Factorial Using Recursion

The document contains C++ code that demonstrates two methods for calculating the factorial of a number: a recursive method (commented out) and an iterative method. The iterative method prompts the user to enter a number and calculates its factorial using a for loop. The result is then printed to the console.

Uploaded by

Abdul Haq
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

#include<iostream>

using namespace std;


//recurcive way to find factorial of number
//int factorial(int n)
//{
// if(n==0)
// {
// return 1;
// }
// int fact=1;
// fact=n*factorial(n-1);
// return fact;
//}
//int main()
//{
// cout<<factorial(5)<<endl;
//}
//itrative way to find factorial
int main()
{
int i, n,fact;
fact=1;
cout<<"Enter number "<<endl;
cin>>n;
for(i=n;i>0;i--)
{
fact=fact*i;
}
cout<<fact;
}

You might also like