Best way to draw circle in C using letters
14,515
You can do something like this:
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
int main()
{
int radius = 16;
int i,j;
for (i=0; i<=2*radius; i++)
{
for (j=0; j<=2*radius; j++)
{
double distance = sqrt((double)(i-radius)*(i-radius) + (j-radius)*(j-radius));
if (distance>radius-0.5 && distance<radius+0.5)
{
printf("*");
}
else
{ printf(" ");}
}
printf("\n");
}
return 0;
}
Author by
Admin
Updated on June 05, 2022Comments
-
Admin almost 2 years
I want to draw a circle using (ASCII) letters like
+
,-
or*
. What is best algorithm for this problem?