on-internet
← Community

Change of program output on the basis of scanf statements in C

Stack Overflow ·

Consider my this program: #include <stdio.h> int factorial (int number) { if (number > 1) return number * factorial(number - 1); } int main() { int input; printf("Find the factorial of: "); scanf("%d", &input); printf("%d", factorial(input)); return 0; } If the user inputs 1, it outputs 1 and if the input is 0, it returns 0, though is was not supposed to, since factorial() function returns a garbage value. But, it works fine with other inputs, for example 2 outputs 2 and so on. Even if the user inputs some negatives like -2 or -3, it outputs the same value as the input. But somehow, if I comme

Comments

Sign in or sign up to comment and upvote.

No comments yet.