Day 89: Factorial Using Recursion of 100DaysCodingChallenge
Hello all,
#day89
Day89
Today's my task was to Write a Program to Find Factorial of a given number N using Recursion. (N is entered by the user).
I have started the 100 days of coding challenge to improve my programming skills..
Code :
//let a = prompt("Enter a Number : ");
// program to find the factorial of a number
function factorial(x) {
// if number is 0
if (x == 0) {
return 1;
}
// if number is positive
else {
return x * factorial(x - 1);
}
}
// take input from the user
const num = prompt('Enter a positive Number: ');
// calling factorial() if num is positive
if (num >= 0) {
const result = factorial(num);
console.log(`The Factorial of ${num} is ${result}`);
}
else {
console.log('Enter a positive Number.');
}
function factorial1(n) {
if (n >= 1) {
return n * factorial(n - 1);
}
}
//console.log(factorial(parseInt(a)));
Output :
Happy Coding:)
Thank you...

Comments
Post a Comment