diff --git a/Project3/.gitignore b/Project3/.gitignore new file mode 100644 index 0000000..d418a2c --- /dev/null +++ b/Project3/.gitignore @@ -0,0 +1,4 @@ +/bin +/obj +/Project3.depend +/Project3.layout diff --git a/Project3/Project3.cbp b/Project3/Project3.cbp new file mode 100644 index 0000000..5c5a7cc --- /dev/null +++ b/Project3/Project3.cbp @@ -0,0 +1,41 @@ + + + + + + diff --git a/Project3/main.c b/Project3/main.c new file mode 100644 index 0000000..f491957 --- /dev/null +++ b/Project3/main.c @@ -0,0 +1,59 @@ +#include + +#define MAX_ROWS 100 +#define MAX_COLS 100 + +int main() { + int n, m; + int A[MAX_ROWS][MAX_COLS]; + + // Input matrix dimensions + printf("Enter the number of rows (n): "); + scanf("%d", &n); + printf("Enter the number of columns (m): "); + scanf("%d", &m); + + // Input matrix elements + printf("Enter the elements of matrix A (%d x %d):\n", n, m); + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + scanf("%d", &A[i][j]); + } + } + + // Replace zero elements + for (int j = 0; j < m; j++) { + int firstNonZero = -1; + + // Find the first non-zero element in the column + for (int i = 0; i < n; i++) { + if (A[i][j] != 0) { + firstNonZero = A[i][j]; + break; + } + } + + // Replace zero elements with the found first non-zero value + if (firstNonZero != -1) { // If a non-zero element was found + for (int i = 0; i < n; i++) { + if (A[i][j] == 0) { + A[i][j] = firstNonZero; + } + } + } + } + + // Output modified matrix + printf("Modified matrix A:\n"); + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + printf("%d ", A[i][j]); + } + printf("\n"); + } + + printf("Press any key to exit...\n"); + getchar(); + getchar(); + return 0; +}