Answer to Question #250734 in C for Hazzy

Question #250734

Exercise 4: Practice to manipulate data in arrays 

Write a C program that read numbers from an integer array and graph the information in the form of 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:15-0400
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>


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




	for(i=0;i<sizeof(values)/sizeof(values[0]);i++){
		counterValues[values[i]]++;
		
	}


	for(i=0;i<10;i++){
		printf("%d %d ",i,counterValues[i]);
		for(j=0;j<counterValues[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