C Program to Draw a Rectangle and Bar Using C Graphics

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.

void rectangle(int xTopLeft, int yTopLeft, int xBottomRight, int yBottomRight);

rectangle function draws a rectangle on screen. It takes the coordinates of top left and bottom right corners.

void bar(int xTopLeft, int yTopLeft, int xBottomRight, int yBottomRight);

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 C graphics program to draw a rectangle and bar
Related Topics
C graphics program to draw an eclipse
C graphics program to draw stars in night sky
C graphics program to draw concentric circles
C graphics program for moving car animation
C program to draw 3D bar graph
C program to draw pie chart using graphics
C program for bouncing ball animation
List of all C Graphics Programs