Fixed the calculation of "r", which had a typo.
Added a bunch of comments and refactored some code for easier reuse.
Added .gitignore file
Added Makefile and a new main.c file for testing.