Advertisement
Guest User

Again c programming

a guest
May 24th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.94 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int min(int arr[], int length)
  4. {
  5.     int ans = arr[0];
  6.     for (int i = 1; i < length; i++)
  7.         if (arr[i] < ans)
  8.             ans = arr[i];
  9.     return(ans);
  10. }
  11.  
  12. int max(int arr[], int length)
  13. {
  14.     int ans = arr[0];
  15.     for (int i = 1; i < length; i++)
  16.         if (arr[i] > ans)
  17.             ans = arr[i];
  18.     return(ans);
  19. }
  20.  
  21. int main()
  22. {
  23.     FILE *ifile, *ofile;
  24.     ifile = fopen("input.txt", "r");
  25.     if (ifile == NULL)
  26.     {
  27.         printf("Create a file and restart a program!");
  28.         return(0);
  29.     }
  30.     ofile = fopen("output.txt", "w");
  31.     int h, w;
  32.     fscanf(ifile, "%d %d", &h, &w);
  33.     int A[h][w];
  34.     for (int i = 0; i < h; i++)
  35.         for (int j = 0; j < w; j++)
  36.             fscanf(ifile, "%d", &A[i][j]);
  37.  
  38.     int M[h];
  39.     for (int i = 0; i < h; i++)
  40.         M[i] = min(A[i], w);
  41.     fprintf(ofile, "%d", max(M, h));
  42.  
  43.     fclose(ifile);
  44.     fclose(ofile);
  45.     return(0);
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement