Drawing a Circle in C

Hey guys,

I have an assignment for a programming class and it is basically to draw a circle inside of a rectangle of user specified dimensions. The radius of the circle is to be half of the smallest dimension(width or height). The picture has to be a PPM image. I know there are much easier ways to accomplish this but we are required to write a loop that prints every pixel individually.

I've got the basic idea but I just can figure out the parameters to use to determine when I print one color(the circle) versus printing another color( the rectangle surrounding the circle). From what I've been able to find is that the formula x^2 * y^2 = r^2 can be of some help but everything I have tried doesn't work. Any ideas would be greatly appreciated.

THanks!

Something along these lines:

why are code tags impossible

Well here's a snippet that might help: linky link

Feel free to ask me to clarify anything. I didn't want to take away all the fun by writing the whole program for you.

Beware, I did not test that math for indexing into the pixel array, but it made sense in my head...

FWIW I'd memset all the pixels to the background color, then draw on top of it where the circle hits.