F How can we draw a bar chart based on the marks of ten student entered by the user using C program ? | CodeTheta

How can we draw a bar chart based on the marks of ten student entered by the user using C program ?

May 18, 2013

This program not tested in my machine so if you will get any error during compile time please send me a report though comment box. Here in this coding you can see the graphics function and standard library function is used

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<stdlib.h>
#define MAX 10
void dda(int, int, int, int);
void main()
{
int x1, y1,i;
int gd=DETECT, gm;
int m[MAX];
initgraph(&gd, &gm, "C:\\TC\\BGI");
x1=getmaxx()/2;
y1=getmaxy()/2;
for(i=0;i<MAX;i++)
{
printf("Enter marks");
scanf("%d", &m[i]);
}
dda(x1,y1,x1,y1+180);
for(i=0; i<MAX; i++)
{
dda(x1,y1,x1+m[i],y1);
y1+=20;
}
getch();
}
void dda(int x1, int y1, int x2, int y2)
{
float x=x1, y=y1, dx, dy;
int len, i;
putpixel(x1, y1, WHITE);
abs(x2-x1)>=abs(y2-y1)?(len=abs(x2-x1)):(len=abs(y2-y1));
dx=(float)(x2-x1)/len;
dy=(float)(y2-y1)/len;
for(i=1; i<=len; i++)
{
x+=dx;
y+=dy;
putpixel((int) x, (int) y, WHITE);
}
return;
}
Try this code in your computer for better understanding. Enjoy the code. If you have any Question you can contact us or mail us

Post a Comment