I'm Required to create a 2 dimensional array, let say its a 12 by 12 2D Array. What i'm requried to do is to place a pair of fix number(1-9) e.g. {1,1},{2,2}{3,3},{4,4},{5,5},{6,6},{7,7},{8,8},{9,9} on a 2D array. These numbers are to have a different position on the 2D array every time the program starts and the remaining array must be blank.
Example: The 2D array will roughly look like this(Let's assume '#' is the frame of the array):
# # # # # # # # # # # #
# 1 9 2 #
# 4 #
# 6 2 8 #
# #
# 1 3 5 #
# #
# 3 6 #
# 4 5 #
# 9 7 #
# 7 8 #
# # # # # # # # # # # #
The one i've done so far is generating random number from 1-9(not pair) to all of the array.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
int array[12][12];
int i,j;
srand((unsigned)time(NULL));
for(i=0;i<10;i++)
{
for(j=0;j<10;j++)
{
array[i][j]=rand()%9+1;
printf("%3d",array[i][j]);
}
printf("\n");
}
return(0);
}
How should i do it anyway?
Aucun commentaire:
Enregistrer un commentaire