You are given a histogram consisting of rectangles of different heights. These heights are represented in an input list, such that [1, 3, 2, 5]
corresponds to the following diagram
#include<iostream>
using namespace std;
int main(){
int n;
cout << "Enter size of the array -> ";
cin >> n;
int a[n],max = 0;
// input
for(int i=0;i<n;i++){
cin >> a[i];
if(a[i] > max){
max = a[i];
}
}
// output
for(int i=max;i>0;i--){
for(int j=0;j<n;j++){
if(a[j] >= i)
cout << "x";
else
cout << " ";
}
cout << endl;
}
}
Top comments (0)