#include <stdio.h>
void conv(int largura, int altura, int linha, int coluna, int original[altura][largura], int resultante[altura][largura]) {
int i, j;
if (linha >= altura - 2 || coluna >= largura - 2) return;
for (i = linha; i < linha + 3; i++) {
for (j = coluna; j < coluna + 3; j++) {
resultante[i][j] = original[i][j] * original[i][j];
}
}
}
void operar(int largura, int altura, int original[altura][largura], int resultante[altura][largura], void (*op)(int largura, int altura, int linha, int coluna, int original[largura][altura], int resultante[altura][largura])) {
int i, j;
for (i = 0; i < altura; i++) {
for (j = 0; j < largura; j++) {
op(largura, altura, i, j, original, resultante);
}
}
}
void imprimir(int largura, int altura, int original[altura][largura]) {
int i, j;
for (i = 0; i < altura; i++) {
for (j = 0; j < largura; j++) {
printf("%5d ", original
[i
][j
]); }
}
}
int main() {
int entrada[5][5] = {{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}, {16, 17, 18, 19, 20}, {21, 22, 23, 24, 25}};
int saida[5][5];
operar(5, 5, entrada, saida, conv);
imprimir(5, 5, entrada);
imprimir(5, 5, saida);
}
I2luY2x1ZGUgPHN0ZGlvLmg+Cgp2b2lkIGNvbnYoaW50IGxhcmd1cmEsIGludCBhbHR1cmEsIGludCBsaW5oYSwgaW50IGNvbHVuYSwgaW50IG9yaWdpbmFsW2FsdHVyYV1bbGFyZ3VyYV0sIGludCByZXN1bHRhbnRlW2FsdHVyYV1bbGFyZ3VyYV0pIHsKICAgIGludCBpLCBqOwogICAgaWYgKGxpbmhhID49IGFsdHVyYSAtIDIgfHwgY29sdW5hID49IGxhcmd1cmEgLSAyKSByZXR1cm47CiAgICBmb3IgKGkgPSBsaW5oYTsgaSA8IGxpbmhhICsgMzsgaSsrKSB7CiAgICAgICAgZm9yIChqID0gY29sdW5hOyBqIDwgY29sdW5hICsgMzsgaisrKSB7CiAgICAgICAgICAgIHJlc3VsdGFudGVbaV1bal0gPSBvcmlnaW5hbFtpXVtqXSAqIG9yaWdpbmFsW2ldW2pdOwogICAgICAgIH0KIC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