Question

What does the following nested loop structure outp
0 0
Add a comment Improve this question Transcribed image text
Answer #1

1)

It print out the triange of @

What happen in code:

   int count = 1;
// loops untill 11
while(count <= 11)
{
int innerCount = 1;
// prints space " " . half the times of 12 - count
while(innerCount <= (12 - count) / 2)
{
cout << " ";
innerCount++;
}
innerCount = 1;
// prints the @ upto number of count
while(innerCount <= count)
{
cout << "@";
innerCount++;
}
cout << endl;
count++;
}

2)

It print out multiples of 1 to 10 upto 10 number and print in rows

Explaination?

int count = 1;
// loops untill 10
while(count <= 10)
{
int innercount = 1;
// loops untill 10 and print count*innercount
while(innercount <= 10)
{
cout << setw(5) << count * innercount;
innercount++;
}
cout << endl;
count++;
}

3)

indata >> number; was repeating twice so there is a chance of skipping first number.

so replace it with

sum = 0;

while(indata>>number)

{
sum = sum + number;
}//end while

Add a comment
Know the answer?
Add Answer to:
What does the following nested loop structure output? count = 1; while (count <= 11) {innerCount...
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
  • 10. The following loop is supposed to sum all of the input values on file indata...

    10. The following loop is supposed to sum all of the input values on file indata Wu wrong with it? Change the code so that it works correctly. sum = 0; indata >> number; while (indata) indata >> number; sum = sum + number;

  • 2. What is the output of the following code fragment? n = 1; while (n <=...

    2. What is the output of the following code fragment? n = 1; while (n <= 5) { n++; cout << n << ' '; a.1 2 3 4 5 b. 1 2 3 4 c. 1 1 1 forever d. 2 3 4 5 e. 2 3 4 5 6 3. What is the termination condition for the following While loop? while (beta > 0 && beta < 10) { cout << beta << endl; cin >> beta; }...

  • What will be the output produced from the following nested loops: sum = 0; a =...

    What will be the output produced from the following nested loops: sum = 0; a = 7; while (a<10) {       for (k = a; k<=10; k++)                   sum +=k;       a++; } cout<< sum << endl; int x, y; for (x = 1; x<=5; x++) {       cout<<x<<endl;       for (y = 2; y <x; y++)                   cout<< y<<endl; }

  • What is the output from each of the following segments of C++ code? Record the output...

    What is the output from each of the following segments of C++ code? Record the output after the “Answer” prompt at the end of each program fragment. Assume all variables have been suitably declared. (Each problem is worth 3 points.) 1. for (int j = 25; j > 16; j -= 3)        cout << setw(5) << j;     Answer: 2. int sum = 0;       for (int k = -2; k <= 2; k++)         sum = sum +...

  • Create a program named Lab14B. You will create a nested loop in this program by putting...

    Create a program named Lab14B. You will create a nested loop in this program by putting Lab14A’s for loop inside a while loop. In the new while loop, you will read integers from the file, Lab14B.txt, and determine if the number is prime (using the copied loop from Lab14A). Stop the while loop when you reach the end of file. Copy your code from Lab14A into your new program Add a while not eof loop around that code, and also...

  • A. What is the output of the following C++ code fragment? (all variables are of type...

    A. What is the output of the following C++ code fragment? (all variables are of type int) int count-1; int y-100; while (count 3) y=y-1 ; count+t cout << y << endl; cout<< count <<endl What is the value of x after control leaves the following while loop? (all variables are of type int) B. int x0 while (x < 20) sum- sum+x cout << sum<< endl;

  • What is the output of the following C++ code? int count = 1; int num =...

    What is the output of the following C++ code? int count = 1; int num = 25; while (count < 25) { num--; count++; } cout << count « " " « num << endl i 25 1 0 24 1 0 25 0 0 24 0 In this while loop statement, while (counter < 10), where counter is an int variable. Which statement below is an equivalent way to write this while statement? while (10 < counter) while (9...

  • What is the output of the following program segment? int count = 5; while(--count > 0)...

    What is the output of the following program segment? int count = 5; while(--count > 0) cout << count << " "; cout << endl;

  • Q. 07 (2 points) Convert the following while loop to a for loop: int count =...

    Q. 07 (2 points) Convert the following while loop to a for loop: int count = 0; while (count<50) cout<<"count iscounts endl count+

  • Lab 5-2 Nested Loops 2. Summation Of Numbers (using Nested While Loops) Part A: The program...

    Lab 5-2 Nested Loops 2. Summation Of Numbers (using Nested While Loops) Part A: The program will calculate and display the total of all numbers up to a specific number (entered by the user). Only positive numbers are allowed. Part B: User-controlled loop Part A Input Validation loop Part A: Summation loop Examples: When 5 is entered the program will calculate the total as 1+2+...+5 and display 15. When 2 is enterered the program will calculate the total as 1+2...

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