[ create a new paste ] login | about

Link: http://codepad.org/jZ4Owwhi    [ raw code | output | fork ]

C, pasted on Dec 7:
#include <stdio.h>
int main()
{
    int n, i;
    unsigned long long factorial = 1;

    printf("Enter an integer: ");
    scanf("%d",&n);

    // show error if the user enters a negative integer
    if (n < 0)
        printf("Error! Factorial of a negative number doesn't exist.");

    else
    {
        for(i=1; i<=n; ++i)
        {
            factorial *= i;              // factorial = factorial*i;
        }
        printf("Factorial of %d = %llu", n, factorial);
    }

    return 0;
}


Output:
1
Enter an integer: Factorial of 134514112 = 0


Create a new paste based on this one


Comments: