Chapter 6 Exercise Set 1: CPE PracticeΒΆ

  1. What is the output of the following program?

    #include <iostream>
    using namespace std;
    
    int main() {
        int i = 12;
        float f = 1000.0;
        while (i > 0) {
            i -= 3;
            f /= 10;
        }
        cout << f << endl;
        return 0;
    }
    
    1. 0.01

    2. 1

    3. 0.1

    4. 10

  2. What is the output of the following program?

    #include <iostream>
    using namespace std;
    
    int main() {
        int i = 12;
        float f = -1.0;
        while (i < 0) {
            f = f + 5.0 * f / -5; 
            --i;
        }
        cout << i << endl;
        return 0;
    }
    
    1. 5

    2. 12

    3. 18

    4. 24