I have no idea what would be wrong with that.
I compiled it using the gcc compiler and it worked perfeclty.
Even the fact that scanf doesn't check for wrong input, in this case it will either cast a non-int to an int, or interpret a string as its numerical value.
Maybe post the entire function to see if something else is causing it.