Life, the Universe, and Everything Your program is to use the brute-force approach in order to find the Answer to  Life, the Universe, and Everything. More precisely... rewrite small numbers from input to output. Stop processing input after reading in the number 42. All 
  numbers at input are integers of one or two digits.


I submitted the code for the above problem on spoj and it says wrong answer even when writing the correct output.

The first solution I submitted was:

#include &lt;stdio.h&gt;
int main(void)
{
    int i;
    while (1) {
        scanf("%d", &amp;i);
        if (i == 42)
            break;
        printf("%d", i);
    }
    return 0;
}


The above solution doesn't check whether the input is two digit or not so I wrote another one:

#include &lt;stdio.h&gt;
int main(void)
{
    int i;
    while (1) {
        scanf("%d", &amp;i);
        if (i &gt; 99)
            continue;
        if (i == 42)
            break;
        printf("%d", i);
    }
    return 0;
}



  ... rewrite small numbers from input to output. All numbers at input ... one or two digits.


However, both of the above solutions don't work on spoj.
Disclaimer: I'm not sure if this code will be the solution for SPOJ.

You don't check if the input number is an int.

if (scanf("%d", &amp;i) == 1)
{
    printf("OK\n");
} 
else
{
    printf("Not an integer.\n");
}




You don't ever tell the user what to enter.

printf("%s\n", "Enter what you think the answer is to life, the universe, and everything (hint: it's a number).");




This is more of a nitpick, but the while loop could be created in a better fashion instead of breaking.

while (i != 42)




Another nitpick, you don't add a newline after printing the int.

printf("%d\n", i);