Because your program is using terminal I/O, you need to run it from a terminal (otherwise it has nowhere to send the output, and will hang waiting for input).
To run it from the terminal, you should invoke it with a preceding './', ie:
You cannot invoke it using only the name (since the default path does not include the current directory; this is done deliberately to prevent the accidental running of malicious programs).