solutionadda

#include <stdio.h>

// Function to find and print the factorial of a number
unsigned long long factorial(int n);

int main() {
    int num;

    // Input from user
    printf("Enter a non-negative integer: ");
    scanf("%d", &num);

    // Check if the input is a non-negative integer
    if (num < 0) {
        printf("Error: Please enter a non-negative integer.\n");
    } else {
        // Call the factorial function and print the result
        printf("Factorial of %d = %llu\n", num, factorial(num));
    }

    return 0;
}

// Recursive function to calculate the factorial of a number
unsigned long long factorial(int n) {
    // Base case: factorial of 0 is 1
    if (n == 0) {
        return 1;
    } else {
        // Recursive case: n! = n * (n-1)!
        return n * factorial(n - 1);
    }
}