Write a C program that read numbers from an integer array and graph the information in the
form of bar chat. Sample output is given below.
Element Value Histogram
0 19 *******************
1 3 ***
2 15 ***************
3 7 *******
4 11 ***********
5 9 *********
6 13 *************
7 5 *****
8 17 *****************
9 1 *
#include <stdio.h>
int main()
{
int arr[] = { 19, 3, 15, 7, 11, 9, 13, 5, 17, 1 };
int size = sizeof(arr) / sizeof (arr[0]);
for (int i = 0; i < size; i++) {
printf("%d %d ", i, arr[i]);
for (int j = 0; j < arr[i]; j++) {
printf("*");
}
printf("\n");
}
return 0;
}
Comments
Leave a comment