Skip to content

Instantly share code, notes, and snippets.

@semreh17
Last active June 7, 2023 10:33
Show Gist options
  • Save semreh17/3be6edf9c22335475b1858cb332ade9e to your computer and use it in GitHub Desktop.
Save semreh17/3be6edf9c22335475b1858cb332ade9e to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define S 31
int main() {
int row = 0, col= 0, i, j, k, l, mat[row][col], len, flag, max;
char nome_file[S];
printf("inserire il nome del file contenente la matrice: ");
scanf("%s", nome_file);
FILE *fp;
printf("inserire la dimensione del quadrato da verificare: ");
scanf("%d", &len);
fp = fopen(nome_file, "r");
if(fp == NULL) {
perror("Errore nell'aprire il file");
return(-1);
}
fscanf(fp, "%d %d", &row, &col);
for(i = 0; i<row; i++) {
//printf("%d ", row);
for(j = 0; j<col; j++) {
fscanf(fp, "%d ", &mat[i][j]);
}
//printf("\n");
}
//scorrere tutti gli elementi della matrice
for(i = 0; i<row; i++) {
for(j = 0; j<col; j++) {
printf("%d ", mat[4][4]);
//controllo
max = mat[i][j];
flag = 0;
for(k = -len; k<=len && !flag; k++) {
for(l = -len; l<=len && !flag; l++) {
if( (k!=0 && l!=0) && ((i+k >= 0 && i+k < row) && (j+l >= 0 && j+l < col))) {
if(max < mat[i + k][j + l]) {
//printf("- ");
flag = 1;
}
}
}
}
if(!flag) {
//printf("%d ", max);
}
}
printf("\n");
}
fclose(fp);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment