-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhist.c
44 lines (40 loc) · 762 Bytes
/
hist.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define NCOLS 120
#define NROWS 25
void
print_hist(int *data, int nr_data)
{
char plot[NCOLS + 1][NROWS + 1];
int i,j,k,nr_dots;
for(i=0;i<NCOLS + 1;i++)
memset(plot[i], ' ', sizeof(plot[i]));
for(i=0;i<NROWS+1;i++)
plot[0][i]='+';
for(i=0; i<NCOLS+1;i++)
plot[i][0]='+';
for(k=0;k<nr_data;k++)
{
nr_dots = data[k]/(100/NROWS);
for(i=1;i<nr_dots;i++)
plot[k+1][i] = '*';
}
for(i=0;i<NROWS+1;i++)
{
for(j=0;j<NCOLS+1;j++)
printf("%c", plot[j][NROWS-i]);
printf("\n");
}
}
int
main()
{
int data[NCOLS - 2];
int i;
srandom(time(NULL));
for(i=0;i<sizeof(data)/sizeof(int);i++)
data[i] = random()%100;
print_hist(data, sizeof(data)/sizeof(int));
return 0;
}