logo CodeStepByStep logo

loopMysteryExam1

Language/Type: C++ while return

For each call of the function below, write the output that is printed and the value that is returned:

int loopMysteryExam1(int i, int j) {
    while (i != 0 && j != 0) {
        i = i / j;
        j = (j - 1) / 2;
        cout << i << " " << j << " ";
    }
    cout << i << endl;
    return i + j;
}
loopMysteryExam1(5, 0) output
loopMysteryExam1(5, 0) return
loopMysteryExam1(3, 2) output
loopMysteryExam1(3, 2) return
loopMysteryExam1(16, 5) output
loopMysteryExam1(16, 5) return
loopMysteryExam1(80, 9) output
loopMysteryExam1(80, 9) return
loopMysteryExam1(1600, 40) output
loopMysteryExam1(1600, 40) return

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.