I asked a much complicated question before here at Generating Unique Random Numbers in an Array using Loop
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.
So right now I am trying to create a 5x5 board using arrays with random numbers..here is my code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
//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 <= 5 ; rows++ )
{
//Create the columns for the board
for ( columns = 1; columns <= 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
The last part board[randomNumber][randomNumber];
is where I think I got really confused. I really don't know what to do with it.
I'm trying to assign random numbers into the board, which I got it awfully wrong.
Any pointers guys?