#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define COL 20
#define ROW 20
void PopulateArray2DUnique(int [][COL], int, int , int , int );
void DisplayArray2D(int [][COL], int, int );
int main()
{
int matrix[ROW][COL], r ,c ,i , j;
int max = 400;
int min = 0;
printf("Enter the amount of rows and cols you would like\n Must be under 20!\n");
scanf("%d%d\n",&r,&c);
PopulateArray2DUnique(matrix,r,c,min,max);
DisplayArray2D(matrix,r,c);
return 0;
}
void PopulateArray2DUnique(int matrix[][COL], int r,int c, int min, int max)
{
int i, j;
srand(time(NULL));
for(i = 0; i<r; i++)
{
for(j = 0; j<c; j++)
{
matrix[i][j] = rand() % (max + min)+min;
}
}
}
void DisplayArray2D(int matrix[][COL], int r,int c)
{
int i,j;
for(i = 0; i < r; i++)
{
for(j = 0; j < c; j++)
{
printf("%4d ", matrix[i][j]);
}
printf("\n");
}
}
what this program does (so far) is ask user to input the size of the matrix, then the function PopulateArray2DUnique generates random values for the matrix!
asks me to input the size of rows and cols twice