title: Drawing histogram from data in array
body: <p>I am attempting to write a function which takes an int array as argument, and writes a histogram with '*' for data in the array. </p>
  
  <p>For example, for int arr[]{2,1,0,7,1,9}, we should get:</p>
  
  <p><a href="https://i.stack.imgur.com/TWuNk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TWuNk.png" alt="histogram"></a></p>
  
  <p>How should I write this code?</p>
  
  <p>My code:</p>
  
  <pre><code>    using namespace std;
  
      int max = 0;
      char znak = '*';
  
      void histo(int arr[], size_t size) {
          for (int i = 0; i &lt; size; i++) {
              if (arr[i] &gt; max)
                  max = arr[i];
          }
  
  //drawing histogram
  
  while (max &gt; 0) {
              for (int i = 0; i &lt; size; i++) {
                  if (arr[i] &gt;= max) {
                      cout &lt;&lt; znak &lt;&lt; " ";
                  }
                  else {
                      cout &lt;&lt; " ";
                  }
              }
              max--;
          }
  
      }
  
  
      int main()
      {
          int arr[]{2,1,0,7,1,9};
          size_t size = sizeof(arr) / sizeof(*arr);
          histo(arr, size);
  
      }
  </code></pre>