Need help with these study question 1. What is the output? int main(void) { int
ID: 3863174 • Letter: N
Question
Need help with these study question
1. What is the output?
int main(void)
{
int fun = 13; int time = 3; int result;
result = fun++ * ++time;
cout << fun << "***" << time << "***" << result << endl;
return 0;
}
2. How many times would the following loop be executed?
int i = 12;
while (i > 0)
{
cout << 2 * i << endl;
i += 2;
}
3. while( n <= 5){
cout << n << " ";
n++;
}
4. How many times would the following loop be executed?
int i = 3;
do
{
cout << 2 * i << endl;
i += 3;
}while (i < 10);
Explanation / Answer
1. The output is
result = fun++ * ++time; //here result is computed using fun value before incrementing and time value
after incrementing
The statement cout << fun << "***" << time << "***" << result << endl;
prints 14***4***52
__________________________________________________
2.The loop runs infinitely because initially i=12 , and it increments continuously and it is greater than zero.
___________________________
3.The loop runs infinitely, if the initial value of n is greater or equal to 6.
Here the initial value of n is not provided.
________________________________________________
4.; The loop runs 4 times.
First time unconditionally executes the loop.
in the second iteration the value of i becomes 6, which is<10,so, it runs again
In the third iteration the value of i becomes 9, which is <10, runs again
In the fourth iteration the value of i becomes 12 which is >10 . so exits from loop.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.