Skip to content

MyUstaadG

Learn to Serve

  • Computer Science
    • Software
    • Computer Tips
    • Coding
      • Conditional Structures Exercises
      • Loops Exercises
      • Arrays Exercises
      • Python Exercises
    • Microsoft Office
      • MS Excel
      • MS Word
  • Videos
    • Funny Videos
    • Health and Fitness Videos
    • PUBG Videos
    • Technology Videos
  • News
  • Funny
  • Memes
  • Playwright Tutorials
  • Tutorials
  • Toggle search form

Write a program that inputs values into a one-dimensional array of ten elements. Draws a bar chart or histogram.

Posted on February 5, 2022February 5, 2022 By myustaadg.com
Spread the love

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:

Introduction to C++ Programming | Download and Install Dev C++ Compiler
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/

Arrays Exercises, Programming Exercises Tags:array in programing, Array simple codes, Arrays, arrays C++ codes, arrays C++ programing exercises, arrays codes, Arrays exercises, Arrays full course, arrays in programing, bar chart in programing, bar chart using arrays, draw a bar chart using arrays, Write a program that inputs values into a one-dimensional array of ten elements. Draws a bar chart or histogram.

Post navigation

Previous Post: Write a program that inputs real values into float type array. It reads the value of each element of float type array and assigns to int type array.
Next Post: Write a program that transposes a matrix A and displays the result on the screen | Transpose of a Matrix.

More Related Articles

Write a program that inserts a new value at a specified location into one-dimensional array of N elements. Arrays Exercises
Write a program that inputs ten values into an array. It finds out the average value of the array Arrays Exercises
Write a program that deletes a value from a specified location of one-dimensional array of N elements. Arrays Exercises
Write a program that inputs values into two linear arrays. It adds the two arrays and stores the sum in the third array. Arrays Exercises
Write a program that inputs employees code, names, and salaries of 10 employees in three arrays ‘code’, ‘name’, and ‘salary’ It computes the net salary. Arrays Exercises
Write a Program to Build a Simple Calculator in Java Write a Program to Make a Simple Calculator in Java Programming Language | Solved Programming Exercises Programming Exercises

Copyright © 2022 MyUstaadG.

Powered by PressBook Blog WordPress theme