Factorial Calculation Problem Statement
Develop a program to compute the factorial of a given integer 'n'.
The factorial of a non-negative integer 'n', denoted as n!
, is the product of all positive integers less than or equal to 'n'.
Explanation:
The factorial is calculated as follows:
n! = n * (n-1) * (n-2) * (n-3) ... * 1
Print the factorial of the given number 'n'. If the factorial is undefined, print 'Error'.
Input:
The only line of input contains a single integer.
Output:
The only line of output should display the factorial of the number or "Error" if it cannot be calculated.
Example:
Input:
5
Output:
120
Constraints:
- -10 <= n <= 12
Note:
The factorial is only defined for non-negative integers. Values of 'n' less than 0 should return 'Error'.

AnswerBot
4mo
Program to compute factorial of a given integer 'n', with error handling for negative values.
Create a function to calculate factorial using a loop or recursion
Check if input is negative, return 'Error...read more
Help your peers!
Add answer anonymously...
Nagarro Software Developer interview questions & answers
A Software Developer was asked 3mo agoQ. Design and implement a data structure for Least Recently Used (LRU) cache. It sh...read more
A Software Developer was asked 3mo agoQ. Given the root of a binary search tree, and an integer k, return the kth smalles...read more
A Software Developer was asked 5mo agoQ. What is abstraction in Java?
Popular interview questions of Software Developer
A Software Developer was asked 3mo agoQ1. Design and implement a data structure for Least Recently Used (LRU) cache. It sh...read more
A Software Developer was asked 3mo agoQ2. Given the root of a binary search tree, and an integer k, return the kth smalles...read more
A Software Developer was asked 5mo agoQ3. What is abstraction in Java?
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

