Added <stdlib.h> library.
Moved main() to the end to avoid 'implicit declaration' warnings.
Defined return values for functions.