First off, after getting the number the user inputs, you are making a call to getchar. This is retrieving the leftover '\n' in the buffer (ASCII code 13?) so x now contains 13.

Structure of a for...