classnotes

classnotes - /* chapter 3_6 */ /* This program generates a...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Sheet1 Page 1 /* chapter 3_6 */ /* This program generates a summary report from a data file that has a trailer record with negative values */ #include <stdio.h> #define FILENAME "sensor2.dat" int main(void) { /* Declare and initialize variables */ int num_data_pts=0 double time, motion, sum=0, max, min FILE *sensor /* Open file and read the first data point */ sensor = fopen(FILENAME, "r") if (sensor == NULL) printf("Error opening input file \n") else { /* Initialize variables using first data point */ max = min = motion /* Update summary data until trailer record read */ do { sum += motion if (motion > max) max = motion if (motion < min) min = motion num_data_pts++ } while (time >= 0) } /* Print summary information */ printf("Number of sensor readings: %d \n",num_data_pts) printf("Average reading:%.2f \n",sum/num_data_pts) printf("Maximum reading:%.2f \n" ,max) printf('Minumum reading:%.2f \n" ,min) /* Close file */ fclose(sensor) } /* Exit program */ return 0 }
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 05/21/2010 for the course EEL 2161 taught by Professor Lopez during the Spring '10 term at FAU.

Page1 / 4

classnotes - /* chapter 3_6 */ /* This program generates a...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online