C Program to generate Graph using grphics.h

C Program to Generate the graph sheet using the grphics.h library. To use graphics.h, we have to install the drivers in to the the system by using the initgraph() function. Here  we derive the graph of input sizes verses time taken for input sizes. x axis represents inputs(0,10000,20000,—-), y axis rep time(0,0.05,0.1,0.15—). Read more about C Programming Language.

/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/

#include "stdio.h"
#include "conio.h"
#include "graphics.h"
void main() {
int gd = DETECT, gm;
int y = 0, x = 10, m[20], k[20], n, a[20], i;
float b[20];
initgraph(&gd, &gm, "c:\tc\bgi");
printf("nntGenerating the Graphsnn");
printf("nEnter the no. of inputst");
scanf("%d", &n);
printf("nEnter the input sizes and corresponding time takenn");
for (i = 0; i < n; i++) {
printf("nEnter input sizet");
scanf("%d", &a[i]);
printf("nEnter time takent");
scanf("%f", &b[i]);
}
cleardevice();
//represents y axis
line(10, 0, 10, 400);
//represents x axis
line(10, 400, 600, 400);
while (y <= 400) {
line(0, y, 10, y);
y = y + 20;
}
while (x <= 600) {
line(x, 400, x, 410);
x = x + 20;
}
outtextxy(20, 440, "1unit=20 pixels , origin is (10,400)");
outtextxy(
20,
450,
"x axis represents inputs(0,10000,20000,----), yaxis rep time(0,0.05,0.1,0.15---)");
setcolor(5);
for (i = 0; i < n; i++) {
k[i] = (a[i] * 0.002);
m[i] = (400 - (b[i] * 400));
putpixel(k[i], m[i], 11);
}
for (i = 0; i < n - 1; i++)
line(k[i], m[i], k[i + 1], m[i + 1]);
getch();
}
Read more Similar C Programs
Learn C Programming

Number System

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

To browse more C Programs visit this link
(c) www.c-program-example.com

One comment on “C Program to generate Graph using grphics.h

  • Aldo Carello says:

    I’m impressed, I have to admit. Seldom do I come across a blog that’s both equally educative and engaging, and let me tell you, you’ve hit the nail on the head. The problem is something which too few folks are speaking intelligently about. Now i’m very happy I came across this during my hunt for something regarding this.

    Reply

Leave a Reply