Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int** fill() {
- FILE* file = fopen("test.txt", "r");
- if (!file) {
- printf("Error occurred while reading a file!");
- return -1;
- }
- int** arr = malloc(5 * sizeof(int*));
- for (int i = 0; i < 5; ++i)
- arr[i] = malloc(6 * sizeof(int));
- if (arr == NULL)
- return -10;
- int number = 0;
- int i = 0, j = 0;
- while (fscanf(file, "%d", &number) > 0)
- {
- arr[j][i++] = number;
- if (i == 6) {
- ++j;
- i = 0;
- }
- }
- fclose(file);
- return arr;
- }
- int main() {
- int** arr = fill();
- int flag = 0;
- for (int i = 0; i < 5; ++i) {
- int min = 9999999;
- int min_arr[] = { 0, 0, 0, 0, 0, 0 };
- for (int j = 0; j < 6; ++j) {
- if (arr[i][j] < min) {
- min = arr[i][j];
- for (int l = 0; l < j; ++l)
- min_arr[l] = 0;
- min_arr[j] = 1;
- }
- else if (arr[i][j] == min)
- min_arr[j] = 1;
- }
- int max = -9999999;
- for (int n = 0; n < 6; ++n) {
- if (min_arr[n] == 0)
- continue;
- int max_idx = 0;
- for (int k = 0; k < 5; ++k) {
- if (arr[k][n] > max) {
- max = arr[k][n];
- max_idx = k;
- }
- }
- if (max == arr[i][n]) {
- flag = 1;
- printf("%d %d \n", i, n);
- }
- }
- }
- if (flag == 0)
- printf("no such elements in given matrix");
- return 0;
- }
- 111 21 3 19 34 -252
- 29 82 92 20 101 123
- 1 -22 33 18 29 -231
- 21 923 75 -232 85 43
- -7 -5 4 3 -20 65
Advertisement
Add Comment
Please, Sign In to add comment