Factorial Cpp

Shared by: this

cpp

1
#include <iostream>
2

3

4
using namespace std;
5

6
int factorial(int number){
7
    if (number == 1){
8
        return number;
9
    };
10
    int factorialSum  = number * factorial(number - 1);
11
    return factorialSum;
12
}
13

14
int main() {
15
    int factorialOf = factorial(7);
16
    cout << factorialOf;
17
    return 0;
18
}
Love it? Share it!

DevCanvas DevCanvas Logo

Online Editor with a collection of awesome frontend code and code snippets for developers of all levels.

Legal & Support

Stand with Palestine 🇵🇸! DO NOT BE SILENCED

© 2025 DevCanvas. All rights reserved.