Question

C++ What will be the output of the following program? (Use _ to represent spaces.) #include...

C++

What will be the output of the following program? (Use _ to represent spaces.)

#include <iostream>
using namespace std;

int main ()
{
     int i = 0;
     int firstNum = 1;
     int secondNum = 1;
     const int max = 10;
     int sum = 0;

     cout << firstNum << “ “;
     do
     {
          cout << secondNum << “ “;
          secondNum += firstNum;
          firstNum = secondNum;
          i++;
     }
     while (i <= max);
     cout << secondNum << “ “;

     return 0;
}
0 0
Add a comment Improve this question Transcribed image text
Answer #1

answer)

output is :

1_1_2_4_8_16_32_64_128_256_512_1024_2048

first  cout << firstNum << " "; this print "1"

net it go to do while loop

do while run 11 times

in do while first it print the value of secondNum

every secondNum is incremented with firstNum(secondNum=secondNum+firstNum)

firstNum is assigned to secondNum.

like wise dowhile runs 11 times

at the end the value of secondNum is printed.

Add a comment
Know the answer?
Add Answer to:
C++ What will be the output of the following program? (Use _ to represent spaces.) #include...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT