Computer scienceProgramming languagesC++Errors, debugging, and exceptions

Exception Handling

Theory

Factorial of n

Report a typo

Modify the C++ program to calculate the factorial of a positive integer 'n'. Implement custom exception handling to handle negative input values and display "Negative input is not allowed. Please enter a non-negative integer." as an error message.

Sample Input 1:

5

Sample Output 1:

120
Write a program in C++
#include <iostream>

int main() {
int n, factorial = 1;

std::cin >> n;

try {

} catch () {

}

return 0;
}

Create a free account to access the full topic