One of my colleagues proposed us a challenge: to write the shortest C/C++ program to determine if a number is even or odd.
These are the requirements:
- Get a number from keyboard, at run-time (not from command line)
- Output the string
pariif the number is even - Output the string
dispariif the number is odd - We can assume that the input is legal
- We can assume that the machine has a i386 architecture
- Code preprocessing is not allowed (e.g.: use
#defines) - [edit after comments] The code can be considered valid if it compiles with
gcc 4.x
This is the best attempt we had so far (file test.c, 50B):
main(i){scanf("%d",&i);puts("dispari"+3*(~i&1));} Do you think we can go further?
(*): "dispari" is the italian for odd and "pari" is the italian for even