Preview:
#include <stdio.h>

int main(void)
{
    int number;
    int result = 1;

    // Prompt the user to input a non-negative whole number
    printf("Enter a non-negative whole number: ");
    scanf("%d", &number);

    // Check if the input is negative
    if (number < 0)
    {
        printf("\nBad Input! %d is negative...\n", number);
        return 1; // Terminate the program with an error code
    }

    // Compute the factorial
    for (int i = number; i >= 1; i--)
    {
        result *= i;
    }

    // Display the factorial result
    printf("\n%d! is %d\n", number, result);

    return 0;
}
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter