C++ Program to find factorial of a number using the function


In this program, You will learn how to find factorial of a number using the function in C++.


3! = 1 * 2 * 3 => 6

Example: How to find factorial of a number using the function in C++.

#include<iostream>
using namespace std;

int factorial(int a) {

    int i, f = 1;
    for (i = 1; i <= a; i++) {
        f = f * i;
    }
    return f;
}

int main() {

    int a, f;

    cout << "Enter a number:";
    cin>>a;

    f = factorial(a);
    cout << "Factorial is:" << f;

    return 0;
}

Output:

Enter a number:3
Factorial is:6

Xiith is created for educational, experimental, and schooling purpose. Examples on Xiith are made easier to make a better or basic understanding. Tutorials, testimonials, and examples are continuously checked to avoid delusion, but we cannot take complete responsibility of all programs on Xiith. When you are operating this site, you have to agree to read and accept our terms of use, cookie and privacy policy.Copyright © 2020 by Xiith. All Rights Reserved. About us.