You are here

Draw shapes using C graphics

This C graphics program draws basic shapes such as circle, line, rectangle, ellipse and display text on screen using C graphics. This can be a first graphics program for a beginner.

C programming code

  1. #include<graphics.h>
  2. #include<conio.h>
  3.  
  4. main()
  5. {
  6.    int gd = DETECT,gm,left=100,top=100,right=200,bottom=200,x= 300,y=150,radius=50;
  7.  
  8.    initgraph(&gd, &gm, "C:\\TC\\BGI");
  9.  
  10.    rectangle(left, top, right, bottom);
  11.    circle(x, y, radius);
  12.    bar(left + 300, top, right + 300, bottom);
  13.    line(left - 10, top + 150, left + 410, top + 150);
  14.    ellipse(x, y + 200, 0, 360, 100, 50);
  15.    outtextxy(left + 100, top + 325, "My first C graphics program");
  16.  
  17.    getch();
  18.    closegraph();
  19.    return 0;
  20. }