c++ home work

1 answer below »
Answered Same DayOct 16, 2021

Answer To: c++ home work

Vaibhav answered on Oct 17 2021
116 Votes
Quiz Solutions
Question 1
How many times will the following loops iterate? Note that the
loops don’t print anything :
int a=10;
while
(a>=0) {
a-=2;
cout<if (a<6 || a>=3)
break;
}
Answer 1: Initially a = 10.
While loop keeps checking the value of a until it becomes less than 0 (i.e negative number). For
each iteration, we decrement the value of a by 2. If during the execution of the loop, the value of
a is either less than 6 or greater than 3, then we break the execution of the for loop. Hence, it
will iterate only once.
Question 2
How many times will the following loops iterate? Note that the
loops don’t print anything :
int a=10;
while (true) {
a-=2;
cout<if (a==6)
break;
}
Answer 2: Initially a = 10.
The while loop will run infinitely as we have provided it with a true value. But for the first
execution, the value of a will become 8 which is not equal to 6. Hence, the while loop will again
execute for the second time. This time, it will update the value of a to 6, which is equal to 6.
Hence, the if block is executed and it will break out of the while loop. Hence, it will iterate
twice.
Question 3
How many times will the following loops iterate? Note that the
loops don’t print anything:
int a=10;
while (a<10){
a-=2;
cout<}
Answer 3: Initially a = 10.
While loop will execute till the value of a is less than...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here