{"id":"f58f68c6-a489-4a30-890d-2ec40ad80e4f","name":"Factorial","description":"1. You are given a number n.\r\n2. You are required to calculate the factorial of the number. Don't change the signature of factorial function.\r\n\r\nNote -> The online judge can't force you to write the function recursively but that is what the spirit of question is.Write recursive and not iterative logic. The purpose of the question is to aid learning recursion and not test you.","inputFormat":"A number n","outputFormat":"factorial of n","constraints":"0 &lt;= n &lt;= 10","sampleCode":{"cpp":{"code":"#include<iostream>\r\nusing namespace std;\r\n\r\nint factorial(int n){\r\n // write your code here\r\n \r\n}\r\n\r\n\r\nint main(){\r\n int n; cin>>n;\r\n cout<<factorial(n);\r\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static void main(String[] args) throws Exception {\r\n // write your code here\r\n }\r\n\r\n public static int factorial(int n){\r\n return 0;\r\n }\r\n\r\n}"},"python":{"code":"def factorial(x):\n # write your code here\n\nnum = int(input())\nprint(factorial(num))"}},"points":10,"difficulty":"easy","sampleInput":"5","sampleOutput":"120","questionVideo":"https://www.youtube.com/embed/zEwwEQi9FAc","hints":[],"associated":[{"id":"0d19df09-96d2-4c44-980a-b2e8dfe62ec5","name":"(Factorial) What is the time complexity of the recursive solution for this solution?","slug":"factorial-what-is-the-time-complexity-of-the-recursive-solution-for-this-solution","type":4},{"id":"0e582090-33bd-4c3e-9dcd-ecf9506f112c","name":"(Factorial) What is expanded form of 7! (7 factorial)?","slug":"factorial-what-is-expanded-form-of-7-7-factorial","type":4},{"id":"caed20c1-d022-4699-bd6e-99cef568c753","name":"(Factorial) What is the value of zero factorial?","slug":"factorial-what-is-the-value-of-zero-factorial","type":4},{"id":"d05a6fba-6ca6-43be-bb28-5e20d261239a","name":"(Factorial) Does factorial of negative numbers exist?","slug":"factorial-does-factorial-of-negative-numbers-exist","type":4}],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"d341a7c9-1269-409c-b851-0bb512289544","name":"Recursion And Backtracking For Beginners","slug":"recursion-and-backtracking-for-beginners","type":0},{"id":"2610d2ba-0b44-4faf-8a58-5d7bafe88564","name":"Factorial","slug":"factorial","type":1}],"next":{"id":"0ed561a5-3298-40cf-aeb3-99b55cdd90ef","name":"Factorial","type":3,"slug":"factorial"},"prev":{"id":"59400822-c4b4-45d7-a9f5-366fcd00b86c","name":"Print Increasing Decreasing","type":3,"slug":"print-increasing-decreasing"}}}

Factorial

1. You are given a number n. 2. You are required to calculate the factorial of the number. Don't change the signature of factorial function. Note -> The online judge can't force you to write the function recursively but that is what the spirit of question is.Write recursive and not iterative logic. The purpose of the question is to aid learning recursion and not test you.

{"id":"f58f68c6-a489-4a30-890d-2ec40ad80e4f","name":"Factorial","description":"1. You are given a number n.\r\n2. You are required to calculate the factorial of the number. Don't change the signature of factorial function.\r\n\r\nNote -> The online judge can't force you to write the function recursively but that is what the spirit of question is.Write recursive and not iterative logic. The purpose of the question is to aid learning recursion and not test you.","inputFormat":"A number n","outputFormat":"factorial of n","constraints":"0 &lt;= n &lt;= 10","sampleCode":{"cpp":{"code":"#include<iostream>\r\nusing namespace std;\r\n\r\nint factorial(int n){\r\n // write your code here\r\n \r\n}\r\n\r\n\r\nint main(){\r\n int n; cin>>n;\r\n cout<<factorial(n);\r\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static void main(String[] args) throws Exception {\r\n // write your code here\r\n }\r\n\r\n public static int factorial(int n){\r\n return 0;\r\n }\r\n\r\n}"},"python":{"code":"def factorial(x):\n # write your code here\n\nnum = int(input())\nprint(factorial(num))"}},"points":10,"difficulty":"easy","sampleInput":"5","sampleOutput":"120","questionVideo":"https://www.youtube.com/embed/zEwwEQi9FAc","hints":[],"associated":[{"id":"0d19df09-96d2-4c44-980a-b2e8dfe62ec5","name":"(Factorial) What is the time complexity of the recursive solution for this solution?","slug":"factorial-what-is-the-time-complexity-of-the-recursive-solution-for-this-solution","type":4},{"id":"0e582090-33bd-4c3e-9dcd-ecf9506f112c","name":"(Factorial) What is expanded form of 7! (7 factorial)?","slug":"factorial-what-is-expanded-form-of-7-7-factorial","type":4},{"id":"caed20c1-d022-4699-bd6e-99cef568c753","name":"(Factorial) What is the value of zero factorial?","slug":"factorial-what-is-the-value-of-zero-factorial","type":4},{"id":"d05a6fba-6ca6-43be-bb28-5e20d261239a","name":"(Factorial) Does factorial of negative numbers exist?","slug":"factorial-does-factorial-of-negative-numbers-exist","type":4}],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"d341a7c9-1269-409c-b851-0bb512289544","name":"Recursion And Backtracking For Beginners","slug":"recursion-and-backtracking-for-beginners","type":0},{"id":"2610d2ba-0b44-4faf-8a58-5d7bafe88564","name":"Factorial","slug":"factorial","type":1}],"next":{"id":"0ed561a5-3298-40cf-aeb3-99b55cdd90ef","name":"Factorial","type":3,"slug":"factorial"},"prev":{"id":"59400822-c4b4-45d7-a9f5-366fcd00b86c","name":"Print Increasing Decreasing","type":3,"slug":"print-increasing-decreasing"}}}
plane

Editor


Loading...

Factorial

easy

1. You are given a number n. 2. You are required to calculate the factorial of the number. Don't change the signature of factorial function. Note -> The online judge can't force you to write the function recursively but that is what the spirit of question is.Write recursive and not iterative logic. The purpose of the question is to aid learning recursion and not test you.

Constraints

0 <= n <= 10

Format

Input

A number n

Output

factorial of n

Example

Sample Input

5

Sample Output

120

Question Video

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode