Question
) For each part below, show the output produced ( exactly as it would appear on the computer screen). Problem 0 is an example. Trace
) For each part below, show the output produced (exactly as it would appear on the computer screen). Problem 0 is an example. Trace these program segments on paper (use a table) and in your head rather than using the C++ compiler.
Prob# | Loop to trace | Output |
0 |
for (int i = 2; i <= 10; i+=2) cout << i << squared = << i*i << endl; | 2 squared = 4 4 squared = 16 6 squared = 36 8 squared = 64 10 squared = 100
|
1 |
for (int i = 3; i >= -3; i --) cout << i << cubed = << i*i*i << endl;
|
|
2 |
for (int i = 1; i <= 5; i++) { cout << i; for (int j = 5; j >= i; j -= 2) cout << j; cout << endl; }
|
|
3 |
int k = 1; for (int i = 5; i >= -4; i-=2) { cout << i + k << endl; k+=i; }
|
|
Page 3
4 |
for (int i = 3; i > 0; i--) for (int j = i; j > 0; j--) for (int k = j; k > 0; k--) cout << i << j << k << endl;
|
|
5 |
for ( int i = 4; i > 1; i--) for (int j = 4; j > 1; j--) { for (int k = j; k >= i; k--) cout << i << j << k << endl; }
|
|
6
|
int i = 6; int k, j = 2; for (;;) { k = 3 * i j; if (k < 0) break; cout << i << j << k << endl; j++; i--; } cout << i << j << k << endl;
|
|
Page 4
7
|
int k = 0; int i = 1; while (k < 7) { cout << log(base 2) of << i << = << k << endl; i *= 2; k++; }
|
|
8
|
int j, i =1; while (i*i < 10) { j = i; while (j*j*j < 100) { cout << i + j << endl; j++; } i++; } cout << ***** ;
|
|
9
|
int k, i = 1; do { k = i * i * i 4 * i + 1; cout << i << k << endl; i++; } while (k <= 20); |
|
10
| int j, k, i = 1; do { j = i * i * i; cout << i; do { k = i + 2*j; cout << j << k; j += 2; } while (k <= 10); cout << endl; i++; } while (j <= 8); |
|
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started