A circle printing program

A circle printing program

/* 
   A program to draw a circular area using ASCII characters.         

   Michael Ashley / UNSW / 12-Mar-2003 
*/

#include <stdio.h>

const int xRange = 40;
const int yRange = 20;
const int radius = 15;

int main () {
    int x, y;

    for (y = -yRange; y < yRange; y++) {
        for (x = -xRange; x < xRange; x++) {
	    if (x*x + y*y > radius * radius) {
	        printf (".");
	    } else {
	        printf ("#");
	    }
	}
	printf ("\n");
    }
    return 0;
}

Note the use of const int definitions to describe dimensions of the drawing. It is good practice to define any special numbers in your program in this way, since it makes the logic easier to understand, and also makes it easier to change a number in the future.

And here is what the output looks like:

................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
........................................#.......................................
...................................###########..................................
.................................###############................................
...............................###################..............................
..............................#####################.............................
.............................#######################............................
............................#########################...........................
............................#########################...........................
...........................###########################..........................
...........................###########################..........................
..........................#############################.........................
..........................#############################.........................
..........................#############################.........................
..........................#############################.........................
..........................#############################.........................
.........................###############################........................
..........................#############################.........................
..........................#############################.........................
..........................#############################.........................
..........................#############################.........................
..........................#############################.........................
...........................###########################..........................
...........................###########################..........................
............................#########################...........................
............................#########################...........................
.............................#######################............................
..............................#####################.............................
...............................###################..............................
.................................###############................................
...................................###########..................................
........................................#.......................................
................................................................................
................................................................................
................................................................................
................................................................................