{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

q4 sol - CSCI.1100 Computer Science I Quiz 4 October 4 2007...

This preview shows pages 1–3. Sign up to view the full content.

CSCI.1100 Computer Science I Quiz 4 October 4, 2007 Closed book, closed notes, no computers or calculators of any kind. Name: RCS login: Circle your lab section: (01 MR 10:00) (02 MR 12:00) (03 MR 2:00) (04 MR 4:00) (05 MR 6:00) (06 MR 10:00) (07 TF 10:00) (08 TF 12:00) (09 MR 12:00) (010 TF 2:00) You will have 15 minutes to complete this test. Make sure you do not spend too much time on any question. The time spent on each question should be proportional to the number of points 1. Here is a square root program with one additional line. Each time through the loop it prints out the value of max, min and guess. If the user enters the number 19, show the first four lines of output (4 points). #include <iostream> using namespace std; int main() { double number, max, min, guess, diff; cout <<"Enter a number greater than one: "; cin >> number; min = 1.0; max = number; while (true) { guess = (max - min)/2 + min;

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

View Full Document
cout << max << " " << min << " " << guess << endl; diff = (guess * guess) - number; if (diff < 0) diff = -diff; if (diff < .00001) break; else { if (guess * guess > number) { max = guess; } else { min= guess; } } } cout << "The square root of " << number << " is " << guess << endl; return 0; } 19 1 10
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}