Write a C program to implement Bar Graph in Graphics

By | 02.12.2016

Implement Bar Graph in Graphics


Write a C program to implement Bar Graph in Graphics. Here’s simple program to implement Bar Graph in Graphics in C Programming Language.


Below is the source code for C program to implement Bar Graph in Graphics which is successfully compiled and run on Windows System to produce desired output as shown below :


SOURCE CODE : :


/*  C program to implement Bar Graph in Graphics  */

#include<graphics.h>
#include<stdio.h>
#include<math.h>
#include<dos.h>
#include<conio.h>
 
void main()
{
        int i,n,a,b;
        void drawrect(int ,int);
 
        int graphdriver = DETECT, graphmode;
        initgraph(&graphdriver, &graphmode, "..\\bgi");
 
        setcolor(CYAN);
        printf("ENTER THE NUMBER OF DATA ELEMENTS\n");
        scanf("%d",&n);
 
        line(1,1,1,479);// Y axis
        line(1,479,640,479);// X axis
 
        for(i=1;i<=25;i++)
        {
                outtextxy(40*i,470,"|");
                outtextxy(1,479-40*i,"-");
        }
 
        printf("ENTER X AND Y CO-ORDINATES \n");
        for(i=1;i<=n;i++)
        {
                scanf("%d %d",&a,&b);
                b--;
                drawrect(a*40,b*40);
        }
        getch();
        closegraph();
}
 
void drawrect(int a,int b)
{
         setfillstyle(SOLID_FILL,CYAN);
         bar3d(a,478,a,430-b,5,1);
}

Above is the source code for C program to implement Bar Graphs in Graphics which is successfully compiled and run on Windows System.The Output of the program is shown above .

If you found any error or any queries related to the above program or any questions or reviews , you wanna to ask from us ,you may Contact Us through our contact Page or you can also comment below in the comment section.We will try our best to reach up to you in short interval.


Thanks for reading the post….

0 0 votes
Article Rating
Category: C Programming Graphic Programs Tags:

About Tunde A

My name is Tunde Ajetomobi, a Tech Enthusiast and Growth Hacker. I enjoy creating helpful content that solves problem across different topics. Codezclub is my way of helping young aspiring programmers and students to hone their skills and find solutions on fundamental programming languages.

Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments