Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Introduction This project does not involves new code. You just need to combine t

ID: 3910226 • Letter: I

Question

Introduction

This project does not involves new code. You just need to combine the code from the past two labs in Project 3. Write a program that employ the printing histogram method you have done in Project 3 Print Histogram lab to handle the printing task in the program you have done in Project 3 Generate Histogram.

Instructions

In this program, you should

Ask the user input and store in an array (see Project 3 Generate Histogram);

Process the array and generate the histogram array ( see Project 3 Generate Histogram);

Display the histogram as stars (see Project 3 Print Histogram).

here is the skeleton code

#include <stdio.h>

void printHistogram ( int *hist, int n );

int main() {


// Data entry

// Processing data to compute histogram


// Printing histogram
printf(" ");
printHistogram(hist, 10);

return 0;
}

void printHistogram(int *hist, int n) {

int i,j;
for(i=0;i<n;i++)
{
printf("[%d] ",i);
for(j=0;j<hist[i];j++)
{
printf("*");
}
printf(" ");
}
}

Explanation / Answer

code:

#include <stdio.h>
#include <stdlib.h>
//function prototype
void printHistogram(int *hist, int n);


int main(int argc, char** argv) {
int hist[10]; //declared array variable for holding ten values
printf("Enter the 10 values :");
//prompt the user to enter the ten values
for(int i = 0; i<10; i++){
do{
scanf("%d",&hist[i]);
}while(hist[i]<0); //if the user enters the negative number the accept the positive number
}
printf(" ");
printHistogram(hist, 10); //calls the function to print histogram

return (EXIT_SUCCESS);
}

//function to print histogram
void printHistogram(int *hist, int n) {
int i, j;
//outer loop for individual values
for (i = 0; i < n; i++) {
printf("[%d] ", i);
for (j = 0; j < hist[i]; j++) {//inner loop for printing "*"
printf("*");
}
printf(" ");
}
}

output:

Enter the 10 values :

5
6
6
10
10
2
3
4
5
6

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

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote