1) What is the output of the following code? for ( int i=1; i<4; i++) { cout <<
ID: 3558117 • Letter: 1
Question
1)
What is the output of the following code?
for (int i=1; i<4; i++)
{
cout << i << " ";
}
Question 2.
What does the following code print?
int ctr, x = 5;
for (ctr = 0; ctr < 3; ctr++)
{
x = x + ctr;
cout << x << " ";
}
cout << ctr;
Question 3.
What is the output of the following loop?
int a = 3, b = 2;
int c = 0;
while (c < 3)
{
a = a + b;
cout << a << " ";
c = c + 1;
}
cout << b;
Question 4.
For loop, while loop or do loop
Explanation / Answer
I can explain:
1) prints 1 2 3 on the screen.
2) prints 5 6 8 in for loop and ctr value will be 3
3) prints 5 7 9 and 2
Do while loop executes atleast once even if the condition in while loop is false
Thank you.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.