here's an example of a TypeScript program that calculates the factorial of a given number:
function factorial(num: number): number {
if (num === 0) {
return 1;
} else {
return num * factorial(num - 1);
}
}
const number = 5 // replace with the number you want to find the factorial of
const result = factorial(number);
console.log(The factorial of ${number} is ${result});
function factorial(num: number): number {
if (num === 0) {
return 1;
} else {
return num * factorial(num - 1);
}
}
const number = 5 // replace with the number you want to find the factorial of
const result = factorial(number);
console.log(The factorial of ${number} is ${result});