2D array histogram

I need to print out asterisks for equal amount of value in this programm,but i'm kinda stuck with it.I guess i need another for loop or maybe not :).Anyway any suggestions?Thanks


#include <iostream>
#include <array>
using namespace std;

int main()
{

int i,j;
const int row=3;
const int col=2;
int array[row][col] = {2, 5, 6, 7, 7, 11};

cout <<endl<<"Elements"<<"\t"<<"Values \t\t"<<"Histogram"<<endl;
for(int i=0;i<=2;i++){
for(int j=0;j<=1;j++){

cout<<"["<<i<<"]"<<"["<<j<<"]"<<"\t\t"<<array[i][j]<<"\t\t"<<"*";
cout<<endl;
}
}
return 0;
}

I'm confused, ¿why is your histogram a matrix instead of an array?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
#include <string>
using namespace std;

int main()
{
   const int row=3, col = 2;
   int arr[row][col] = {2, 5, 6, 7, 7, 11};

   cout << "Elements\tValues\tHistogram\n";
   for ( int i = 0; i < row; i++ )
   {
      for ( int j = 0; j < col; j++ )
      {
         cout << "[" << i << "]" << "[" << j << "]" << "\t\t" << arr[i][j] << '\t' << string( arr[i][j], '*' ) << '\n';
      }
   }
}
Thanks :)
Topic archived. No new replies allowed.