Question: C programming needed Introduction Write a program that will print a histogram stored in an array. The input histogram array has 10 elements corresponding to

C programming needed

Introduction

Write a program that will print a histogram stored in an array. The input histogram array has 10 elements corresponding to number 0 through 9. The value in the array represents the count of the number. In the following sample histogram, hist[1] equals 5, which means the count of number 1 is 5. In the output, you need to display the number in a bracket followed by certain amount of star characters. The amount of stars equals the count of the number.

Instruction

Start with the given code template. Write your logic in the printHistgram function.

Although we have not covered function yet, it is simple. Just add your code at the position right after the comment: // your code here. Use hist array as input data and print the histogram to screen. The size parameters (worked same way as variable) stores number 10.

With this histogram example: int hist[10] = {0, 5, 3, 2, 0, 3, 2, 1, 2, 2}

Sample run input/output (you should see this when you run your code interactively on your PC)

[0] [1] ***** [2] *** [3] ** [4] [5] *** [6] ** [7] * [8] ** [9] ** 

Hint: You will need nested loop to print the histogram. First layer of loop iterate through rows while second layer of loop displays stars. There is a single space character after [0] and [4].

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!