CPS 125 Midterm: CPS125 Winter 2008 Programming Questions

30 views4 pages
31 Jan 2019
Course
Professor

Document Summary

Questions from the cps125 final exam - winter 2008. Write a complete c program consisting only of a main program that will read from a file (named pairs. txt) pairs of numbers: a double followed by an integer. We do not know how many pairs there are but all pairs are complete. Your program must calculate pair by pair the division of the double by the integer and print on a separate line each quotient with three decimals precision. Finally your program will display on a separate line the number of pairs followed by the word. For example if the file contains 4. 5 3 6. 6 2, your program will display. #include int main (void) int npairs=0, integer; double doubl; File *in; in = fopen ("pairs. txt", "r"); while (fscanf(in, "%lf %d", &doubl, &integer)!=eof) npairs = npairs + 1; printf ("%. 3lf\n", doubl/integer); fclose (in); return (0);