# Thread: Odd results on user input array

1. ## Odd results on user input array

More of less on a whim I decided to write a program to convert matrices into row echelon form. To start off, I wrote a program that took numbers from the user and wrote them into a matrix, then display that matrix.

Code:
```#include <stdio.h>
#include <stdlib.h>

int main(void)
{
int c;
int i, j;
int nr_row, nr_column;

float mat[nr_row][nr_column];

printf("Number of rows: ");
scanf(" %i", &nr_row);
printf("\nNumber of columns: ");
scanf(" %i", &nr_column);

printf("\nInput matrix elements:");
for (i = 0; i < nr_row; i++){
for (j = 0; j < nr_column; j++)
{
printf("\nInput element [%d][%d]: ", i, j);
scanf("%f", &mat[i][j]);
}
}

printf("===========================================");
printf("\nMatrix entered-\n");

for (i = 0; i < nr_row; i++)
{
printf("\n");
for (j = 0; j < nr_column; j++)
{
printf("%7.2f", mat[i][j]);
}
}

return 0;
}```
However, somewhere along the line the values are changed somehow-

Code:
```Number of rows: 4

Number of columns: 2

Input matrix elements:
Input element [0][0]: 1

Input element [0][1]: 5

Input element [1][0]: 54

Input element [1][1]: 88

Input element [2][0]: 12

Input element [2][1]: 48

Input element [3][0]: 13

Input element [3][1]: 52
===========================================
Matrix entered-

1.00  54.00
54.00  12.00
12.00  13.00
13.00  52.00```
Another run-
Code:
```Number of rows: 3

Number of columns: 3

Input matrix elements:
Input element [0][0]: 1

Input element [0][1]: 8

Input element [0][2]: 4

Input element [1][0]: 56

Input element [1][1]: 12

Input element [1][2]: 3

Input element [2][0]: 45

Input element [2][1]: 78

Input element [2][2]: 9
===========================================
Matrix entered-

1.00  56.00  45.00
56.00  45.00  78.00
45.00  78.00   9.00```

2. Code:
```	int nr_row, nr_column;

float mat[nr_row][nr_column];```
You have to know the values of nr_row and nr_column before you declare mat.

Quzah.

3. Code:
```	int nr_row, nr_column;

float mat[nr_row][nr_column];

printf("Number of rows: ");
scanf(" %i", &nr_row);
printf("\nNumber of columns: ");
scanf(" %i", &nr_column);```
Look closely... that the time you are creating the array, you cannot possibly know the number of rows or columns, in fact nr_row and nr_column are used in a totally uninitialized state... you input their values *after* creating the array.

4. Oh my, there's that crystal ball working over time again... another double header... Hi Quzah...

5. Thanks! That fixed things up.