Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Basicly, you'll first make an array (RandomArray) filled with some random numbers between 1 and 5.</p> <pre><code>Random rnd = new Random(); int[] RandomArray = new int[5]; for (int i = 0; i &lt; 5; ++i) { RandomArray[i] = rnd.Next(1, 5); } </code></pre> <p>++i and i++ in this case will do the same.<br> Actually ++i means to first add 1 before taking the value and i++ means take the value of i and add one. But as I said, this doesn't make a difference in here</p> <p>Then you'll make a new array (Count) and you'll count those random numbers.<br> Because the random numbers are between 1 and 5, you'll need to subtract 1 from the number, otherwise you'll have OutOfBound Exceptions.</p> <pre><code>int[] Count = new int[5]; for (int i = 0; i &lt; 5; ++i) { Count[RandomArray[i]-1]++; } </code></pre> <p>After that, you'll print the results as a histogram, using a * for each counted number. Previously, you had to use i-1 to prevent OutOfBounds Exceptions. This means that the counts of the number 1 are stored under index 0, so add 1 add the end to display the correct result</p> <pre><code>for (int i = 0; i &lt; 5; ++i) { Console.Write("{0,2} Adet {1,2} &gt;&gt;&gt;&gt;", Count[i], i+1); for (int j = 0; j &lt; Count[i]; j++) { Console.Write("*"); } Console.WriteLine(); } </code></pre> <p><strong>Example</strong></p> <pre><code>RandomArray = [1, 3, 4, 1, 5]; Count = [2, 0, 1, 1, 1]; 2 Adet 1 &gt;&gt;&gt;&gt; ** 0 Adet 2 &gt;&gt;&gt;&gt; 1 Adet 3 &gt;&gt;&gt;&gt; * 1 Adet 4 &gt;&gt;&gt;&gt; * 1 Adet 5 &gt;&gt;&gt;&gt; * </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload