Trace the execution of the loop below for an input of 32. Modify the code segment so that it uses a for loop instead of the while loop.


1 num1 = 1;
2 cout << "Enter a number=> ";
3 cin >> num2;
4 while ((num2 % 13) != 0) {
5 cout << num1 << " " << num2 << endl;
6 num1 += 1;
7 num2 -= 3;
8 }
9 cout << num2 << " is divisible by 13." << endl;



Line Number num1 num2 Effect
? ?


Line Number num1 num2 Effect
? ?
1 1
2 Displays Enter a number=>
3 32
4 6 != 0 is true
5 Displays 1 32
6 2
7 29
8 Back to line 4
4 3 != 0 is true
5 Displays 2 29
Line Number num1 num2 Effect
6 3
7 26
8 Back to line 4
4 0 != 0 is false
9 Displays 26 is divisible by 13.

Replace lines 3 and 4 by


for (cin >> num2; (num2 % 13) != 0; num2 -= 3) {

and delete line 7

Computer Science & Information Technology

You might also like to view...

Consider the class definition:

``` class IntPair{ int first; int second;public: IntPair(int firstValue, int secondValue);// prefix operator++ here // postfix operator ++ here int getFirst( ) const; int getSecond( ) const; ``` a) Give declarations for prefix and postfix versions of operator++ b) Give definitions for prefix and postfix versions of operator++

Computer Science & Information Technology

Which two statements about sleep-and-charge ports are true? (Select two.)

A) All USB 3.0 and higher ports are sleep-and-charge ports. B) The computer can be sleeping and still provide power to an external device. C) Sleep-and-charge ports are only for USB ports. D) Sleep-and-charge ports require a higher voltage power supply. E) A powered off computer can still provide power to a device connected to a sleep-and-charge port. F) Sleep-and-charge ports require a special cable to be attached in order to work.

Computer Science & Information Technology

?If variable input data is needed, a _____ must be provided to explain what is needed.

A. ?dialog box B. ?list box C. ?menu bar D. ?toggle button

Computer Science & Information Technology

Practice green computing by ____

A. using products that have the Energy Star logo  B. discarding old electronics using municipal curbside waste pickup C. frequently purchasing the latest electronic gadget D. all of the above

Computer Science & Information Technology