The "rectangle" function is used to draw a rectangle in graphics mode.
void rectangle(int left, int top, int right, int bottom);
The "rectangle" function accepts 4 parameters
#include <graphics.h> #include <stdlib.h> #include <stdio.h> #include <conio.h> int main() { int gm,gd=DETECT; int left,top,right,bottom; printf("\nEnter the top left co-ordinate of rectangle(x,y) : "); scanf("%d%d",&left,&top); printf("\nEnter the bottom right co-ordinate of rectangle(x,y) : "); scanf("%d%d",&right,&bottom); initgraph(&gd,&gm,"C:\\turboc3\\bgi"); setcolor(10); rectangle(left,top,right,bottom); getch(); closegraph(); return 0; }
Image Of Getting Co-ordinates
![]()
Final Output