Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- double dohvati_max(double num1, double num2, double num3, double num4) {
- double max = num1;
- if (num2 > max) max = num2;
- if (num3 > max) max = num3;
- if (num4 > max) max = num4;
- return max;
- }
- double** max_pool_2d(double** mat, int N, int M) {
- double** rezMat = (double**) calloc(N/2, sizeof(double*));
- for (int i = 0, indexI = 0; i < N; i += 2, indexI++) {
- rezMat[indexI] = (double*) calloc(M/2, sizeof(double));
- for (int j = 0, indexJ = 0; j < M; j += 2, indexJ++) {
- rezMat[indexI][indexJ] = dohvati_max(mat[i][j], mat[i][j + 1], mat[i + 1][j], mat[i + 1][j + 1]);
- }
- }
- return rezMat;
- }
- int main() {
- int N;
- int M;
- scanf("%d %d", &N, &M);
- if(N % 2 != 0 || M % 2 != 0) {
- printf("Dimenzije ulazne matrice moraju biti parne.");
- return 0;
- }
- double** mat = (double**) calloc(N, sizeof(double*));
- for (int i = 0; i < N; i++) {
- mat[i] = (double*) calloc(M, sizeof(double));
- for (int j = 0; j < M; j++) {
- scanf("%lf", &mat[i][j]);
- }
- }
- FILE* fout = fopen("pool.txt", "w");
- double** rezMat = max_pool_2d(mat, N, M);
- for (int i = 0; i < N/2; i++) {
- for (int j = 0; j < M/2; j++) {
- fprintf(fout, "%.3f ", rezMat[i][j]);
- }
- fprintf(fout, "\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement