I wrote a code to print 5x6 matrix of numbers, but i'm trying to figure out how can I make numbers within matrix random (if possible, within interval). How similar is it to getting random numbers in rows?
int row[50]
srand(time(NULL));
for(i=0;i<50;i++){
row[i]=rand()%31+10;
printf("%d ", row[i]);
}
I used this code earlier today for 50 random numbers within 10-40 interval.
You can use two for loops:
int array[5][6];
srand(time(NULL));
int x, y;
for(x = 0; x < 5; x++) {
for(y = 0; y < 6; y++)
array[x][y] = rand() % 31 + 10;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With