Last active
November 27, 2016 13:57
-
-
Save vladyio/b5b164c314e390eeaeb112d7afa2f978 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Если минимальные элементы столбцов находятся на побочной диагонали и образуют неубывающую последовательность, | |
то транспонировать матрицу. В противном случае матрицу оставить без изменения. | |
*/ | |
#include <stdio.h> | |
void matrix(void); | |
// Global variables declaration | |
int n, A[20][20]; | |
int main () { | |
int i,j; | |
printf("Type in size: "); | |
scanf("%d", &n); | |
for (i=0; i<n; i++) { | |
for (j=0; j<n; j++) { | |
printf("A[%d][%d]= ",i, j); | |
scanf("%d", &A[i][j]); | |
} | |
} | |
matrix(); | |
getchar(); | |
return 0; | |
} | |
void matrix() { | |
int i, j, A_2[n], min, k = 0, ref = 0, buf; | |
for (j = 0; j < n; j++) { | |
// min = get minimal element in line | |
// 3 2 1 [i][j] | |
// 1 2 4 | |
// 3 4 5 | |
min = A[0][j]; | |
for (i = 0; i < n; i++) { | |
if (A[i][j] < min) { | |
min = A[i][j]; | |
} | |
} | |
for (i = 0; i < n; i++) { | |
if (min == A[i][n-i-1]) { | |
A_2[j]=min; | |
} else { | |
printf("Минимальные элементы столбцов не лежат на побочной\n"); | |
break; | |
} | |
} | |
} | |
for (i = 1; i < n; i++) { | |
if (A_2[k] < A_2[i]) { | |
n=i; | |
ref=1; | |
} else { | |
printf("Минимальные элементы не образуют неубывающую последовательность \n"); | |
ref=0; | |
break; | |
} | |
} | |
if (ref == 1) { | |
for (i = 0; i < n; i++) { | |
for (j = 0; j < n; j++) { | |
buf=A[i][j]; | |
A[i][j]=A[j][i]; | |
A[j][i]=buf; | |
} | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment