Homework 13
#include <stdio.h> #include <math.h> #define N 25 #define FILENAME "grid1.txt" int main(void) { /* Declare variables. */ int nrows, ncols, i, j, count = 0; double elevation[N][N]; FILE *grid; int hi, hj, li, lj, highest = 0, lowest = 10000; /* Read information from a data file. */ grid = fopen(FILENAME,"r"); if (grid == NULL) printf("Error opening input file\n"); else { fscanf(grid,"%d %d",&nrows,&ncols); for (i=0; i<=nrows-1; i++) for (j=0; j<=ncols-1; j++) { fscanf(grid,"%lf",&elevation[i][j]); if (elevation[i][j] > highest) { highest = elevation[i][j]; hi = i; hj = j; } else if (elevation[i][j] < lowest) { lowest = elevation[i][j]; li = i; lj = j; } } /* Determine and print peak locations. */ printf("Top left point defined as row 0, column 0 \n"); for (i=1; i<=nrows-2; i++) for (j=1; j<=ncols-2; j++) { if ((elevation[i-1][...