Note that there are some explanatory texts on larger screens.

plurals
  1. POPrint a simple board of 5 x 5 with Array and Loop with Random Numbers
    primarykey
    data
    text
    <p>I asked a much complicated question before here at <a href="https://stackoverflow.com/questions/19362167/generating-unique-random-numbers-in-an-array-using-loop/19365614#19365614">Generating Unique Random Numbers in an Array using Loop</a></p> <p>But I found out I just can't understand all the concepts yet and that there are too many things unknown, so I decided to learn it step by step.</p> <p>So right now I am trying to create a 5x5 board using arrays with random numbers..here is my code:</p> <pre><code> #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;time.h&gt; //Declare the board size and other variables// //Create the random number generator seed //Loop to create the wanted board size //Plant the random numbers into the board within the loop int main() { //Initialize Variables int randomNumber; int rows; int columns; //Declare board size. Size of board is 5 x 5 int board[5][5]; //Create the random number generator seed srand(time(NULL)); //Assign the random numbers from 1 - 25 into variable randomNumber randomNumber = rand() %25 + 1; //Create the rows for the board for ( rows = 1; rows &lt;= 5 ; rows++ ) { //Create the columns for the board for ( columns = 1; columns &lt;= 5 ; columns++ ) { //Assign variable randomNumber into variable board board[randomNumber][randomNumber]; } //Newline after the end of 5th column. printf("\n"); } //Print the board printf("%d\t", board[randomNumber][randomNumber]); }//end main </code></pre> <p>The last part <code>board[randomNumber][randomNumber];</code> is where I think I got really confused. I really don't know what to do with it.</p> <p>I'm trying to assign random numbers into the board, which I got it awfully wrong.</p> <p>Any pointers guys?</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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