You are to recursively draw circles as shown below 1 User wi
You are to recursively draw circles as shown below.
1. User will give a radius as argument within the range of 10 – 50 and the x and y coordinate that will become the center of the circle. Fix coordinates of the center point of the circle at x = 100 and y = 50.
2. Implement a function drawCircles that is recursive (calls itself)
3. The function must draw a circle of radius sent in parameter.
4. Must call itself with new radius that is half of the last circle drawn, in such a way that all circles touch the circumference of each other (like in the diagram below. HINT: keep y coordinate same for every call and change x coordinate by adding the (old_radius + new_radius) into it! ) and keep getting smaller until the radius becomes 1 and then it must stop.
HINT: Use library graphics.h for drawing
NOTE: The code should be in C Language. Thanks.
ALSO: The software I use is \" DEV C++ \".
Solution
#include<stdio.h>
#include<graphics.h>
#include<conio.h>
int main(){
int gd = DETECT,gm;
int x ,y ,radius=100;
initgraph(&gd, &gm, \"C:\\\\TC\\\\BGI\");
x = 100;
y = 50;
drawCirclecircle(radius, y, x);
getch();
closegraph();
return 0;
}
void drawCircle(int radius, int y, int x)
{
circle(x,y, radius);
if(radius < =1)
return;
return drawCircle(radius/2, y, (x+(x/2)));
}
