So the question is to develop a [5][5] table, each containing unique numbers from 1-100 (no duplicates)
so here's what I came up with:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
int outerLoop;
int innerLoop;
int board[5][5]; /* Array Name And Size*/
/* seeds the random number generator*/
srand(time(NULL));
int number;
number = rand() % 101;
/* Start a loop to generate a random integer between 1 and 100 and
assign it into the array. The loop runs 25 times*/
for ( outerLoop = 0 ; outerLoop <= 25 ; outerLoop++ ) /* loop 25 times*/
{
for ( innerLoop = 0 ; innerLoop <= 4 ; innerLoop++ ) /* <=4 due to 5
columns*/
{
board[outerLoop][innerLoop] = rand() % 100 + 1;
}
printf( "%d
", board[outerLoop][innerLoop] );
}
So I pretty much got stuck here.I'm not really sure about this:
board[outerLoop][innerLoop] = rand() % 100 + 1;
I simply made it up :/ Any idea guys?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…