classnotes - chapter 3_6 This program generates a summary...

Info icon This preview shows pages 1–3. 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 { fscanf(sensor,"%lf %lf",&time,&motion) /* 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++ fscanf(sensor,"%lf %lf",&time,&motion) } 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 }
Image of page 1

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

View Full Document Right Arrow Icon
Sheet1 Page 2 /* chapter 3_7 */ /* This program generates a summary report from
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern