Draw Rectangle using C Graphics
Here you will learn and get the example code to draw rectangle in computer graphics.
A rectangle is a four-sided flat shape with straight sides, four right angles, and opposite sides of equal length. It has two pairs of parallel sides. This shape is commonly found in geometry, architecture, and everyday objects.
What is rectangle function in computer graphics?
Rectangle function in computer graphics is used to draw a rectangle on the screen. It has four parameters. The syntax to draw a rectangle is the following:
Syntax:
rectangle(x1,y1,x2,y2);
Here x1,y1 are the top left corner of the rectangle shape and x2,y2 are the bottom right corners of the rectangle shape.
Program code to Draw Rectangle
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | // Draw a rectangle in c graphics #include <stdio.h> #include <conio.h> #include <graphics.h> int main() { int gd = DETECT, gm; int x1,y1,x2,y2; initgraph(&gd, &gm, "C:\\Turboc3\\BGI"); // Coordinates of the rectangle printf("\nEnter the coordinate(x1,y1,x2,y2) : "); scanf("%d%d%d%d",&x1,&y1,&x2,&y2); rectangle(x1, y1, x2, y2); getch(); closegraph(); return 0; } |
Output