Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction To Constraint Databases

Authors: Peter Revesz

1st Edition

1441931554, 978-1441931559

More Books

Students also viewed these Databases questions

Question

Distinguish between poor and good positive and neutral messages.

Answered: 1 week ago

Question

Describe the four specific guidelines for using the direct plan.

Answered: 1 week ago