Write a program that inputs values into one-dimensional array of ten elements. It reads the values of array elements one by one and draws a bar chart or histogram. For example, if first and second element of the array have values 19 and 8 respectively then the output should be as:
Element Value Histogram
0. 19 *******************
1. 8 ********
The entered value for each element should be between 1 to 30.
So let’s Write Code:
Write a program that inputs values into a one-dimensional array of ten elements. Draws a bar chart or histogram.
#include<iostream> using namespace std; main() { int arr[10],i=0; while(i<=9) { cout<<"Value for element "<<i<<" ? "; cin>>arr[i]; if(arr[i]>30 || arr[i]<=0) continue; i++; } i = 0; cout<<"\nElement\tValue\tHistogram\n"; while(i<=9) { cout<<i<<"\t"<<arr[i]<<"\t"; for(int c=1; c<=arr[i]; c++) cout<<"*"; cout<<endl; i++; } }
Hope You will learn Something. Happy Coding.
Visit my YouTube Channel as Well😇 https://www.youtube.com/watch?v=JuIHQ9cLSEw&list=PLbIhkHxfUIItTdcyCb34uRIrPJbXBndIl&index=4
Click on the below Links for more Programming Exercises:
Conditional Structure Exercises: 👉https://myustaadg.com/category/programming-exercises/conditional-structures-exercises/
Array Exercises: 👉https://myustaadg.com/category/programming-exercises/arrays-exercises/