Here is a C program to draw a rectangle and a bar on screen using graphics.h header file. In this program, we will draw a rectangle and a bar on screen. We will use rectangle and bar functions of graphics.h header file to draw rectangle and bar on screen. Below is the detailed descriptions if these two functions.
rectangle function draws a rectangle on screen. It takes the coordinates of top left and bottom right corners.
bar function draws a rectangle and fill it with current fill pattern and color.
Function Argument | Description |
---|---|
xTopLeft | X coordinate of top left corner. |
yTopLeft | Y coordinate of top left corner. |
xBottomRight | X coordinate of bottom right corner. |
yBottomRight | Y coordinate of bottom right corner. |
C program to draw rectangle and bar using graphics
#include<stdio.h> #include<graphics.h> int main(){ int gd = DETECT,gm; initgraph(&gd, &gm, "C:\\TC\\BGI"); /* Draw rectangle on screen */ rectangle(150, 50, 400, 150); /* Draw Bar on screen */ bar(150, 200, 400, 350); closegraph(); return 0; }Program Output
Related Topics