Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int min(int arr[], int length)
- {
- int ans = arr[0];
- for (int i = 1; i < length; i++)
- if (arr[i] < ans)
- ans = arr[i];
- return(ans);
- }
- int max(int arr[], int length)
- {
- int ans = arr[0];
- for (int i = 1; i < length; i++)
- if (arr[i] > ans)
- ans = arr[i];
- return(ans);
- }
- int main()
- {
- FILE *ifile, *ofile;
- ifile = fopen("input.txt", "r");
- if (ifile == NULL)
- {
- printf("Create a file and restart a program!");
- return(0);
- }
- ofile = fopen("output.txt", "w");
- int h, w;
- fscanf(ifile, "%d %d", &h, &w);
- int A[h][w];
- for (int i = 0; i < h; i++)
- for (int j = 0; j < w; j++)
- fscanf(ifile, "%d", &A[i][j]);
- int M[h];
- for (int i = 0; i < h; i++)
- M[i] = min(A[i], w);
- fprintf(ofile, "%d", max(M, h));
- fclose(ifile);
- fclose(ofile);
- return(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement