{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# q4 sol8 - CSCI.1100 Computer Science I Quiz 4 October 5...

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

CSCI.1100 Computer Science I Quiz 4 October 5, 2009 Closed book, closed notes, no computers or calculators of any kind. Name: RCS login: Circle your lab section: (01 MTh 10:00) (02 MTh 12:00) (03 MTh 2:00) (04 MTh 4:00) (05 MTh 6:00) (06 MTh 10:00) (07 TF 10:00) (08 TF 12:00) (09 MTh 12:00) (10 TF 2:00) (11 MTh 4: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 16, show the first three lines of output (9 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) {

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

View Full Document
guess = (max - min)/2 + min; 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
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 3

q4 sol8 - CSCI.1100 Computer Science I Quiz 4 October 5...

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

View Full Document
Ask a homework question - tutors are online