Thread: Printing a circle with different symbols

1. Printing a circle with different symbols

Here's what i've got so far:
Code:
```int r1, r2, x, y, hyp, i;
char grid [30][30];

scanf("%d", &r1);
scanf("%d", &r2);

i = (pow(x,2) + pow(y,2));
hyp = sqrt(i);

for(x = -30; x < 30; x++) {
for (y = -30; y < 30; y++) {
if(sqrt(pow(x,2) + pow(y,2)) > r1 * 2)
printf(" ");
else if(hyp < r1 * 2 && hyp > r2 * 2)
printf("\$");
else if(hyp <= r2 * 2)
printf("*");
}
printf("\n");
}```
This is what it's supposed to look like:
Code:
```   ***********
***************
*****************
*******************
*********************
***********************
*************************
*************************
**********\$\$\$\$\$\$\$**********
*********\$\$\$\$\$\$\$\$\$*********
********\$\$\$\$\$\$\$\$\$\$\$********
********\$\$\$\$\$\$\$\$\$\$\$********
********\$\$\$\$\$+\$\$\$\$\$********
********\$\$\$\$+++\$\$\$\$********
********\$\$\$\$\$+\$\$\$\$\$********
********\$\$\$\$\$\$\$\$\$\$\$********
********\$\$\$\$\$\$\$\$\$\$\$********
*********\$\$\$\$\$\$\$\$\$*********
**********\$\$\$\$\$\$\$**********
*************************
*************************
***********************
*********************
*******************
*****************
***************
***********```
But all I get is a full circle of *'s can anyone help me out with the math?

2. it probably don' t go insede the print (\$)...when i had such exercises it helped to draw in paper an array and see little by little what happens...i think this is something you can easy do...just be a little patient! ...

3. This looks very dodgy:
Code:
```if(sqrt(pow(x,2) + pow(y,2)) > r1 * 2)
printf(" ");```
Looking at a right angle triangle, with sides of 3, 4, & 5 - this is true:
9 + 16 = 25 (Asqr + Bsqr) = Csqr

but sqrt(9+16) = 5, and I don't see that necessarily equaling r1*2. (The diameter of the circle).

Shouldn't the center of the wheel be your reference, so the radius is what you want to compare 5 with, instead?

BTW, if you want it to look like a wheel or tire, multiply the figure times something like 2.6 (depending on the height to width ratio of your console font, and it prints out something that looks pretty good. (When it's working right, of course)