KleptsovKD 5 месяцев назад
Родитель fa9db06256
Сommit e3a01d1eb3

4
Project3/.gitignore поставляемый

@ -0,0 +1,4 @@
/bin
/obj
/Project3.depend
/Project3.layout

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="Project3" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/Project3" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Debug/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-g" />
</Compiler>
</Target>
<Target title="Release">
<Option output="bin/Release/Project3" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Release/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O2" />
</Compiler>
<Linker>
<Add option="-s" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-Wall" />
</Compiler>
<Unit filename="main.c">
<Option compilerVar="CC" />
</Unit>
<Extensions>
<lib_finder disable_auto="1" />
</Extensions>
</Project>
</CodeBlocks_project_file>

@ -0,0 +1,59 @@
#include <stdio.h>
#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;
}
Загрузка…
Отмена
Сохранить