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.
However, somewhere along the line the values are changed somehow-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; }
Another run-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
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



LinkBack URL
About LinkBacks


