circle

Download Circle

If you can't read please download the document

Upload: cesar-jackson

Post on 20-Sep-2015

212 views

Category:

Documents


0 download

DESCRIPTION

Write a program to print a circle.

TRANSCRIPT

C: Printing A CircleThis program will demonstrate how a circle (text based) can be printed in the C console application.We start with the headers.//WinterNurf Productions#include #include #include Next, we begin the main() function and declare two loop control integer variables.int main(){ int nX = 0; int nY = 0;We now declare a character variable and initialize it with the ASCII value 219. I've used this value because this prints a solid block on the screen. Feel free to use any other character in its place. char chBlock = 219;Now, to print the circle, we will create a nested loop. We first create an outer loop for the y - axis. for (nY = 18; nY > 5; nY--)Next comes the inner loop for the x - axis. Be sure to loop 80 times here because the width of the console application is 80 characters, and so we won't need to print a newline character every time a row ends. for (nX = -39; nX -18; nY--) for (nX = -39; nX