Day 13 Oct 10




For homework we had to write a program that printed the peaks and valleys in feet
here the code
/* */
/* This program determines the locations of peaks in an */
/* grid of elevation data. */
#include <stdio.h>
#define N 25
#define FILENAME "grid1.txt"
int main(void)
{
/* Declare variables. */
int nrows, ncols, i, j;
double elevation[N][N];
int total=0;
int distance=0;
FILE *grid;
/* 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]);

/* Determine and print peak locations. */
printf("Top left point defined as row 0, column 0 \n");
int count=0;
for (i=1; i<=nrows-2; i++)
for (j=1; j<=ncols-2; j++)
{

if ((elevation[i-1][j]<elevation[i][j]) &&
(elevation[i+1][j]<elevation[i][j]) &&
(elevation[i][j-1]<elevation[i][j]) &&
(elevation[i][j+1]<elevation[i][j])&&
(elevation[i-1][j-1]<elevation[i][j]) &&
(elevation[i+1][j+1]<elevation[i][j]) &&
(elevation[i-1][j-1]<elevation[i][j]) &&
(elevation[i+1][j+1]<elevation[i][j]))



printf("Peak at row: %d column: %d \n",i,j);





if ((elevation[i-1][j]>elevation[i][j]) &&
(elevation[i+1][j]>elevation[i][j]) &&
(elevation[i][j-1]>elevation[i][j]) &&
(elevation[i][j+1]>elevation[i][j])&&
(elevation[i-1][j-1]>elevation[i][j]) &&
(elevation[i+1][j+1]>elevation[i][j]) &&
(elevation[i-1][j-1]>elevation[i][j]) &&
(elevation[i+1][j+1]>elevation[i][j]))

printf("Valley at row: %d column: %d \n",i,j);
distance=(i*i+j*j)*.5*100;
printf("Distance from [0][0] is %i ft \n",distance);

//count++;
//printf("Number of Peaks is %i \n",count);
}
fclose(grid); /* Close file. */
}
return 0; /* Exit program. */

}

///////////////////
a screencap of the code


For lab we had to connect a speaker to a IC2 temperature sensor, and have the speaker go off after it reached a certain temperature.

Here's a link to a video

Here's a picture

Comments

Popular posts from this blog

Day 5

Day 22 Nov 14

Day 21 Nov 9