You have been given a positive integer N. You need to find and print the Factorial of this number. The Factorial of a positive integer N refers to the product of all numbers in the range from 1 to N.
Example:
Input: n = 5
Output: 120
Approach
C++
#include <bits/stdc++.h>using namespace std;int fact(int n){if (n <= 1)return n;return n * fact(n - 1);}int main(){int n = 5;cout << fact(n) << "\n";return 0;}
No comments:
Post a Comment