rectangle

Overview :

The "rectangle" function is used to draw a rectangle in graphics mode.

Syntax :
void rectangle(int left, int top, int right, int bottom);
Description :

The "rectangle" function accepts 4 parameters

  • left -> The x co-ordinate of the upper left point of rectangle

  • top -> The y co-ordinate of the upper left point of rectangle

  • right -> The x co-ordinate of the lower right point of rectangle

  • bottom -> The y co-ordinate of the lower right point of rectangle

"rectangle" function does not return any value.

Example :
#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

Comments

comments powered by Disqus