C++ Factorial Code Example

Last Updated On Friday 16th Jul 2021

Example

	#include<iostream>
using namespace std;
class Factorial{
    public:
    static int findFactorialIterative(int number){
        int factorial=1;
        for(int i=number;i>0;i--){
            factorial = factorial * i;
        }
        return factorial;
    }
};
int main(){
    cout<<Factorial::findFactorialIterative(4)<<endl; // 24
    cout<<Factorial::findFactorialIterative(5)<<endl; // 120
}