0

I want to code a matrix calculator, and for that I need to ask the user for it's size,but when I'm declaring a 2d array it won't let me put a variable as a size, so what can I do?

    int main()
{
    int n;
    print_enter_matrix_size();
    scanf("%d", &n);
  int matrix[n][n];
    return 0;
}
  • You're going to have to set the size of the array dynamically at runtime using something such as `malloc`. – h0r53 Nov 25 '19 at 18:48
  • [C: Initializing a dynamically typed 2D matrix inside another function](//stackoverflow.com/a/46382784) – 001 Nov 25 '19 at 18:49

1 Answers1

0

You can use dynamics arrays. For that you can use malloc to declare the size you want, Try this: allocate matrix in C