codeform

#include <iostream>
using namespace std;

// Function to calculate the factorial of a number
int factorial(int n) {
    if (n == 0 || n == 1) {
        return 1;
    } else {
        return n * factorial(n - 1);
    }
}

// Main function
int main() {
    // Declare variables
    int num;

    // Prompt user for input
    cout << "Enter a non-negative integer: ";
    cin >> num;

    // Check if the input is non-negative
    if (num < 0) {
        cout << "Please enter a non-negative integer." << endl;
        return 1; // Exit with an error code
    }

    // Calculate and display the factorial
    cout << "Factorial of " << num << " = " << factorial(num) << endl;

    return 0; // Exit successfully
}