Answer to Question #250301 in C for Hazzy

Question #250301

Write a C program that reads numbers from an integer array and graph the information in the form of a bar chart. The 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 *


1
Expert's answer
2021-10-13T06:25:17-0400
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>


void main( void){
	int integerArray[]={1,2,3,5,8,4,5,8,7,4,2,4,5,6,5,1,2,2,5,6,2,2,5,5,5,6,9,5,2,3,6,5,4,5,5,5,6};
	int counterArray[10]={0};
	int i,j;


	for(i=0;i<sizeof(integerArray)/sizeof(integerArray[0]);i++){
		counterArray[integerArray[i]]++;
		
	}


	for(i=0;i<10;i++){
		printf("%d %d ",i,counterArray[i]);
		for(j=0;j<counterArray[i];j++){
			printf("*");
		}
		printf("\n");
	}
	getchar();
	getchar();
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS