In this article we have shown some examples like drawing rectangle, square and circle in C.
1. Write a program to display Tribhuvan University inside a rectangle.
#include<conio.h>
#include<graphics.h>
void main()
{
clrscr();
int gd=DETECT,gm;
initgraph(&gd,&gm,"C:\\TURBOC3\\bgi");
rectangle(200,150,500,300);
settextstyle(1,0,1);
outtextxy(250,225,"Tribhuvan University");
getch();
closegraph();
}
2. WAP to draw a square and a circle and fill a pattern in both of them.
#include<conio.h>
#include<graphics.h>
void main()
{
clrscr();
int gd=DETECT,gm;
initgraph(&gd,&gm,"C:\\TURBOC3\\bgi");
rectangle(100,100,200,200);
setfillstyle(BKSLASH_FILL,RED);
floodfill(105,105,WHITE);
circle(300,300,70);
setfillstyle(LINE_FILL,GREEN);
floodfill(305,305,WHITE);
getch();
closegraph();
}
3. WAP to input x coordinate, y coordinate, radius and draw a circle.
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
clrscr();
int gd=DETECT,gm,x,y,r;
printf("Enter the x-coordinate, y-coordinate and radius of circle:");
scanf("%d%d%d",&x,&y,&r);
initgraph(&gd,&gm,"C:\\TURBOC3\\bgi");
circle(x,y,r);
getch();
closegraph();
}
4. WAP to draw 10 concentric circles with different colors.
#include<dos.h>
#include<conio.h>
#include<graphics.h>
void main()
{
clrscr();
int gd=DETECT,gm,i;
initgraph(&gd,&gm,"C:\\TURBOC3\\bgi");
for(i=1;i<=10;i++)
{
setcolor(i);
circle(200,150,i*10);
delay(500);
}
getch();
closegraph();
}