davide1409

ese3.c

Jan 14th, 2021 (edited)
626
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.81 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3.  
  4. #define M 3
  5. #define N 4
  6.  
  7.  
  8. int Min(int row, int m, int n, int A[m][n], int start, int end){
  9.     int min = A[row][start];
  10.     for(int i = start; i!=end+1; i++){
  11.         if(A[row][i]<min){
  12.             min = A[row][i];
  13.         }
  14.     }
  15.  
  16.     return min;
  17. }
  18.  
  19. int *minPorzioni(register const int m, register const int n, register int A[m][n], int I[m][2]){
  20.     int *vet = malloc(sizeof(*vet) * m);
  21.    
  22.     for(int i = 0; i!=m; i++){
  23.             vet[i] = Min(i, m, n, A, I[i][0]<=0 ? 0 : I[i][0], I[i][1]>=n ? n-1 : I[i][1] );
  24.     }
  25.  
  26.     return vet;
  27. }
  28.  
  29.  
  30.  
  31. int main(void){
  32.     int *ptr;
  33.     int A[M][N] = { {1,7,2,5}, {2,5,1,0}, {8,3,4,2} };
  34.         int I[M][2] = { {2,3}, {-1,5}, {0,2} };
  35.     ptr = minPorzioni(M, N, A, I);
  36.    
  37.     for(int i = 0; i!=M; i++){
  38.         printf("%d,  ", ptr[i]);
  39.     }
  40.  
  41.     puts("");
  42.    
  43.     free(ptr);
  44.     return 0;
  45. }
  46.  
Add Comment
Please, Sign In to add comment