Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #define M 3
- #define N 4
- int Min(int row, int m, int n, int A[m][n], int start, int end){
- int min = A[row][start];
- for(int i = start; i!=end+1; i++){
- if(A[row][i]<min){
- min = A[row][i];
- }
- }
- return min;
- }
- int *minPorzioni(register const int m, register const int n, register int A[m][n], int I[m][2]){
- int *vet = malloc(sizeof(*vet) * m);
- for(int i = 0; i!=m; i++){
- vet[i] = Min(i, m, n, A, I[i][0]<=0 ? 0 : I[i][0], I[i][1]>=n ? n-1 : I[i][1] );
- }
- return vet;
- }
- int main(void){
- int *ptr;
- int A[M][N] = { {1,7,2,5}, {2,5,1,0}, {8,3,4,2} };
- int I[M][2] = { {2,3}, {-1,5}, {0,2} };
- ptr = minPorzioni(M, N, A, I);
- for(int i = 0; i!=M; i++){
- printf("%d, ", ptr[i]);
- }
- puts("");
- free(ptr);
- return 0;
- }
Add Comment
Please, Sign In to add comment