Advertisement
Guest User

Untitled

a guest
Dec 21st, 2014
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.93 KB | None | 0 0
  1. void HistogramArray(int arr1)
  2. {
  3.     int i, s, num = 0; // declaring and initialize variables
  4.     int new_arr[21] = { 0 }; // declaring and initialize a new array
  5.  
  6.     for (i = 0; i < 14; i++)
  7.     { // start of the first loop //
  8.  
  9.         num = arr1[i]; // copy the content //
  10.         new_arr[num] = s++; // save the amount of times that the number is written //
  11.  
  12.     } // end of the first loop //
  13.  
  14.     printf("\nValue\tHistogram\n"); // inform the user //
  15.  
  16.     for (i = 0; i < 20; i++)
  17.     { // start of the external printing loop - printing numbers //
  18.  
  19.         if (new_arr[i] != 0)
  20.         { // only if the numbers appeared in the original array //
  21.             printf("\n%d\t", i); // print the numbers between 1 - 20 //
  22.  
  23.             while (new_arr[i] != 0)
  24.             { // start of the inner printing loop - printing stars //
  25.  
  26.                 printf("*");
  27.                 s--;
  28.             } // end of the inner printing loop //
  29.         } // end of the 'if' term //
  30.     } // end of the external printing loop //
  31. } // end of function //
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement