Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- /*-----------For example: factorial(6) = 1*2*3*4*5*6 = 720-----------*/
- using namespace std;
- int factorial (int f)
- {
- if (f == 1)
- {
- return 1;
- }
- else
- {
- return f * factorial(f-1);
- }
- }
- int main()
- {
- int f;
- cin >> f;
- cout << "factorial(" << f << "): " << factorial(f);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement