title: Horizontal and vertical histogram of an array in C
body: <p>I need to get the horizontal and vertical histogram a given array. Following is the C - code that I tried. Is there any way to improve this or any easy alternate method?</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #define size 10
  int main() {
    int array[size] = {2, 5, 7, 8, 10, 16, 7, 4, 3, 4};
    int i, j, bigCount, temp;
  
   /* To get Horizontal Histogram */
    for (i = 0; i &lt; size; ++i) {
      printf("\n%3d|", i);
      for (j = 0; j &lt; array[i]; ++j)
        printf(" #");
    }
  
    /* To find the biggest count */
    bigCount = array[0];
    for (i = 0; i &lt; size; ++i)
      if(array[i] &gt; bigCount)
        bigCount = array[i];
    temp = bigCount;
    printf("\n\n");
  
    /* To get Vertical Histogram */
    for (i = 0; i &lt; bigCount; ++i) {
      printf("\n%3d|", bigCount - i);
       for (j = 0; j &lt; size; ++j)
         if (array[j] &lt; temp)
       printf("   ");
         else {
       printf("  #");
       --array[j];
         }
       --temp;
    }
  
   /* printing the x-axis */
    printf("\n    ");
    for (i = 0; i &lt; size; ++i) 
      printf("  -", i);
    printf("\n    ");
    for (i = 0; i &lt; size; ++i) 
      printf("%3d", i);
    printf("\n");
    return 0;
  </code></pre>
  
  <p>}</p>