Sunday, 10 April 2016

Program to draw circle using Cartesian coordinates

C++ program to draw a circle using Cartesian Coordinates technique 

Solution:

#include<iostream.h>
#include<graphics.h>
#include<conio.h>
#include<math.h>
void main()
{
int xc, yc, x, y, r;
cout<<"please enter center point of the circle";
cin>>xc>>yc;
cout<<"please enter the radius of the circle";
cin>>r;
int gd=DETECT, gm;
initgraph(&gd,&gm, "..\\bgi");
for(x=r-xc; x<=r+xc; x++)
{
y=yc+sqrt((r*r-(x-xc)*(x-xc)));
putpixel(x,y, RED);
y=yc-sqrt((r*r-(x-xc)*(x-xc)));
putpixel(x,y, BLUE);
}
getch();
}




output: 



4 comments: