Factorial of a Number
Write a program to find the factorial of a number.
Factorial of n is:
n! = n * (n-1) * (n-2) * (n-3)....* 1
Output the factorial of 'n'. If it does not exist, output 'Error'.
Input format :
The only line of input contains a single integer.
Output format :
The only line of output prints the Factorial of the number or "Error" if it doesn't exist.
Constraints:
-10 <= n <= 12
CodingNinjas
author
2y
Using while() loop
- This can be done using an if-else-if ladder to check for negative,0, and positive numbers.
- If the input is a positive number use a while loop to multiply n with n-1, n-2…1 and get the...read more
CodingNinjas
author
2y
Using for() loop
- This can be done using an if-else conditional statement to check for negative, and positive numbers.
- If the input is a positive number use a for loop to multiply n with n-1, n-2…1 and g...read more
Help your peers!
Add answer anonymously...
Top Nagarro Software Developer interview questions & answers
Popular interview questions of Software Developer
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app