My task is to create a matrix of random numbers of nxn size. However, there is an error I canīt solve, it is telling me that the expression needs to have a constant value (on the variable "matrix" in the for loop). What am I doing wrong?
Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
int main()
{
srand(NULL);
int rows;
int columns;
printf("define the size of the matrix\n number of rows\n");
scanf_s("%d", &rows);
printf("number of columns\n");
scanf_s("%d", &columns);
const int x=rows;
const int y=columns;
for (int i = 1; i < x; ++i)
{
for (int j = 1; j <y; ++j)
{
int matrix[x][y] = rand() % 21 + (-10);
printf("%d ", matrix[i][j]);
}
printf("\n");
}
}