Created
November 27, 2016 16:36
-
-
Save vladyio/6ff8d6915bb202f16d47d063ac91b770 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
// Найти максимальный элемент среди элементов, меньших t. | |
#include <stdio.h> | |
#include <stdlib.h> | |
int matrix(void); | |
// Global variables declaration | |
int n, A[20][20], t; | |
int main () { ; | |
int i, j; | |
printf("Type in size: "); | |
scanf("%d", &n); | |
printf("Type in [t]:"); | |
scanf("%d", &t); | |
for (i=0; i<n; i++) { | |
for (j=0; j<n; j++) { | |
printf("A[%d][%d]= ", i, j); | |
scanf("%d", &A[i][j]); | |
} | |
printf("\n"); | |
} | |
printf("максимальный элемент среди элементов, меньших t: %d\n", matrix()); | |
getchar(); | |
return 0; | |
} | |
int matrix() { | |
int i, j, i_lt, j_lt, max, _lt = 0; | |
for (i = 0; i < n; i++) { | |
for (j = 0; j < n; j++) { | |
if (A[i][j] < t) { | |
_lt = 1; // elem < t exists? | |
//printf("\ni = %d, j = %d, a[i,j]=%d", i, j, A[i][j]); | |
i_lt = i; | |
j_lt = j; | |
break; | |
} | |
} | |
} | |
if (!_lt) { | |
printf("Элементов меньше t не дано.\n"); | |
exit(0); | |
} | |
max = A[i_lt][j_lt]; | |
//printf("\ndbg max: %d", max); | |
for (i=i_lt + 1; i<n; i++) { | |
for (j=j_lt + 1; j<n; j++) { | |
if (A[i][j] < t && max < A[i][j]) { | |
max = A[i][j]; | |
} | |
} | |
} | |
return max; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment