Factorials with C

view full story

http://www.daniweb.com – Hello, I've been working with C trying to get factorials which I've successfully accomplished but my code needs to output an error message when inputting negative numbers, unfortunately my code outputs an error when using 1 and 0. This is what my code looks like (keep in mind I'm a beginner user so my code is simple). #include <stdio.h> int main() { int x, number, fac; fac = 1; printf("Enter a number:\n"); scanf("%d",&number); for(x = 1; x <= number; x++) { if (number >= 0) fac = fac * x; } if (number >= 0 && fac != 1) printf("%d! = %d\n", number, fac); else printf("Factorial not defined for negative numbers.\n"); } (General)