Question
Can someone help me start this program? any help is appreciated :) Introduction Write a program that will print a histogram stored in an array.
Can someone help me start this program? any help is appreciated :)
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
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] **
#include
/** * Prints a histogram to the screen using horizontal bar chart. * Parameters: * list - a list of integers * n - the number of values in the list */ void printHistogram ( int *hist, int n );
int main() { const int SIZE = 10; int hist[] = {0, 5, 3, 2, 0, 3, 2, 1, 2, 2};
printHistogram(hist, SIZE);
}
void printHistogram(int *hist, int n) { // your code here }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started