# Thread: making graphs in C

1. ## making graphs in C

does anyone here know the simplest way to make graphs in C?coz im planning to make a millionaires game with a graph that will somehow display the percentage of the audience choice of a particular answer:like a.50% b.25% c.15% d.10%????

if possible pls show the code on how to make it coz im a bit confused with how for loops are to be used here???

2. uhm..all i know is that im usin Linux C compiler.......i was wonderin how to make exact code for the graphs which i was told that can be done usin some loops???

3. What Salem is saying is that for Graphics, you need a library and/or API because you can't just do this. I'm not familiar with Linux programming, so I can't help you out there...

4. It's possible to make a histogram if you use 'x' to shade in. I guess you would want a pie chart though.

5. Originally posted by Nick
It's possible to make a histogram if you use 'x' to shade in. I guess you would want a pie chart though.
ummm,can you like make a sample source code of that coz im kinda a newbie??pls.

6. Code:
```#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define N 70
#define MAX_BLOCKS 22

void create_sin_distr(double freq[], int n)
{
int i;
for (i = 0; i < n; ++i)
freq[i] = fabs(sin((4.0 * M_PI * i)/n));
}

int main(void)
{
int i, j;
double freq[N];
int blocks[N];

create_sin_distr(freq, N);
for (i = 0; i < N; ++i)
blocks[i] = MAX_BLOCKS * freq[i];

for (i = MAX_BLOCKS; i >= 1; --i) {
for (j = 0; j < N; ++j) {
if (blocks[j] >= i)
putchar('X');
else
putchar(' ');
}
putchar('\n');
}

return 0;
}```

7. ## Graphics

if u wanna play w/ graphics under linux use ncurses.h

named appropriate 'cause u'll calling a few curses while trying to code it.

but if u wanna keep it simple...just print a char so many times at location x,y