Goldman Sachs Interview Question
Software Engineer in TestsA Horizontal Histogram
#include <iostream>
using namespace std;
int main()
{
int array[] = {5, 10, 20, 4, 15};
int temp = 0;
for(int i =0;i<sizeof(array)/sizeof(int);i++)
{
if(array[i] > temp)
temp = array[i];
}
for(int i=temp;i>0;i--)
{
cout<<i;
if(i<10)
cout<<" ";
for(int a=0;a<sizeof(array)/sizeof(int);a++)
{
if(array[a] >= i)
cout<<"*";
else
cout<<" ";
}
cout<<endl;
}
}
The following program should work for the horizontal histrogram.
- Des April 12, 2010