Nov 25, 2017 Awais Liaqat

Find Factorial Of Given Number In C++ | CPP
2   0   13   Programming - C++

Facebook   Twitter   Google   Email
post-img
 

Introduction

In this post you will learn how to find factorial using different method in programming languages or c++


Recursive Funtion to find factorial

#include<iostream>
using namespace std;
int find_factorial(int n)
{
    if(n == 1)
    {
        return 1;
    }
    else
    {
        return n = n * find_factorial( n - 1 );
    }
}
int main()
{
    int num;
    cout<<"Enter to number to find Factorial: ";
    cin>>num;
    num = find_factorial( num );
    cout<<"Factorial of number is: "<<num;
    return 0;
}

Simple code without function to find factorial

#include<iostream>
using namespace std;
int main()
{
    int num, fact = 1;
    cout<<"Enter a number to find factorial : ";
    cin>>num;
    for(int i = num; i > 0; i--)
    {
        fact = fact * i;
    }
    cout<<"Factorial of "<<num<<" is "<<fact;
    return 0;
}

Is this helpful?   Yes   No

Facebook   Twitter   Google   Email
Click to copy
Successfully copy the link to share

Leave a Comment


Comments (0)


Thank you for your feedback
You are now following
Request Sent! Wait for Approval
Removed From Following
Something wents wrong!
Thank you for your comment