Monday, January 27, 2020

How to draw concentric circles in C-Language?

Circle: it is locus of points equidistant  from  center . It means all points on circle are of distance r  from center point (xc,yc) in all sides.

Concentric circles: 

circles with same center point (xc,yc) and different radius are called concentric circles.

using direct circle() function from graphics library and for loop  we can draw concentric circles.delay() function from dos.h can be used for seeing circle plotting one circle at a time.

Program to draw concentric circles:

#include<stdio.h>
#include<graphics.h>
#include<conio.h>
#include<dos.h>
void main()
{
 int gd=DETECT,gm,i,xc,yc,r;
 initgraph(&gd,&gm,"c:\\turboc3\\bgi");
 printf("Enter center points");
 scanf("%d %d",&xc,&yc);
 printf("Enter radius of outer circle");
 scanf("%d",&r);
 circle(xc,yc,r);
 for(i=1;i<=r;i++)
 {
  delay(100);
  setcolor(i);
  circle(xc,yc,i);
 }
getch();

}

Output: