您可以用这个字符(■)来表示图表中的计数。这是一个可以打印的字符
printf("%c", (char)254u);
考虑一些随机的float_arr
and hist
保存计数的数组。
Code
// Function generating random data
for (i = 0; i < n; i++){
float random = ((float)rand() / (float)(RAND_MAX));
float_arr[i] = random;
printf("%f ", random);
}
//Dividing float data into bins
for (i = 0; i < n; i++){
for (j = 1; j <= bins; j++){
float bin_max = (float)j / (float)bins;
if (float_arr[i] <= bin_max){
hist[j]++;
break;
}
}
}
// Plotting histogram
printf("\n\nHistogram of Float data\n");
for (i = 1; i <= bins; i++)
{
count = hist[i];
printf("0.%d |", i - 1);
for (j = 0; j < count; j++)
{
printf("%c", (char)254u);
}
printf("\n");
}
Output
Histogram of Float data
0.0 |■■■■■■■■■■■■■■■■■■■■■■
0.1 |■■■■■■■■■■■■■■■■
0.2 |■■■■■
0.3 |■■■■■■■■■■■■■■
0.4 |■■■■■■■■
0.5 |■■■■■■■■■■■■■■■■
0.6 |■■■■■■■■■■
0.7 |■■■■■■■
0.8 |■■■■■■■■■■■■■■■
0.9 |■■■■■■■
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)