Question

In: Computer Science

How many times will an "X" appear in the following nested loop? for (outer = 0;...

How many times will an "X" appear in the following nested loop?
for (outer = 0; outer <=5; outer++)
{for (inner = 1; inner <=4; inner+1)
{cout<<("X");}
}

9

10

20

24

none of the above

Solutions

Expert Solution

answer option D

we can see that in the post condition of the inner loop it is mentioned just inner+1

so it is like

inner +1 ;

so the value of inner is always 1 and leads to infinite loop

#include <bits/stdc++.h>

using namespace std;

int main()

{

    int outer, inner;

    for (outer = 0; outer <= 5; outer++)

    {

        for (inner = 1; inner <= 4; inner + 1)

        {

            cout << "The value of inner is " << inner << endl;

            cout << ("X");

        }

    }

    return 0;

}


Related Solutions

Create a PL/SQL anonymous block that uses a nested loop (inner loop 1 to 15; outer...
Create a PL/SQL anonymous block that uses a nested loop (inner loop 1 to 15; outer loop 1 to 5) to perform computations using the SQL functions, ABS, EXP, SQRT, ROUND, MIN, MAX, LOG, MOD, REMAINDER and POWER The outer loop will use the functions, ABS, EXP, SQRT, ROUND to display the following messages (must be “ The absolute value of <outer loop index> is <value>” “ The value of e to the <outer loop index> power is <value>” “...
How many times will the following while loop iterate? int i = 1; while (i <...
How many times will the following while loop iterate? int i = 1; while (i < 5) {     i = i + 1;     System.out.println(“Hello!”); } Group of answer choices 4 0 5 It will iterate infinitely
How many times will the following crontab entry execute during January 2018? 0 0 * 1...
How many times will the following crontab entry execute during January 2018? 0 0 * 1 1 rm -r /root/backup/* How many times will the following crontab entry execute during January 2018? 0 0 * 1 6 rm -r /root/backup/* List all of the dates the following crontab entry will execute during 2018 (this answer is a little tricky). 0 0 1/10 * 7 rm -r /root/backup/*
How many times is "invalid" displayed in the following loop? for (int k=o; k<3; K++) {...
How many times is "invalid" displayed in the following loop? for (int k=o; k<3; K++) { for(int j =0; j < 4; j++) { cout << "invalid"; } }
(C++) Write a nested loop that reads an integer n (n>0) from the keyboard and print...
(C++) Write a nested loop that reads an integer n (n>0) from the keyboard and print out "n" lines as follows: 0 0 1 0 1 2 0 1 2 3 … 0 1 2 3 … n-1
Determine how many times the innermost loop will be iterated when the algorithm segment is implemented...
Determine how many times the innermost loop will be iterated when the algorithm segment is implemented and run. (Assume that m and n are positive integers.) for j := 1 to m     for k := 1 to n         [Statements in body of inner loop.         None contain branching statements that         lead outside the loop.]     next k next j
Write a program that produces the following output using nested for loop in Java. ****** ////////////...
Write a program that produces the following output using nested for loop in Java. ****** //////////// ****** ***** //////////\\ ***** **** ////////\\\\ **** *** //////\\\\\\ *** ** ////\\\\\\\\ ** * //\\\\\\\\\\ * \\\\\\\\\\\\
must use python Write a nested for loop that displays the following output using the same...
must use python Write a nested for loop that displays the following output using the same integer from part a:                                                     1                                                 1   2   1                                             1   2   4   2   1                                         1   2   4   8   4   2   1                                     1   2   4   8 16   8   4   2   1                                 1   2   4   8 16 32 16   8   4   2   1                             1   2   4   8 16 32 64 32 16   8   4   2   1                         1   2   4  ...
How many arrangements of INCONSISTENT are there in which NE appear consecutively or NO appear consecutively...
How many arrangements of INCONSISTENT are there in which NE appear consecutively or NO appear consecutively but not both NE and NO are consecutive? The answer is 2x11!/2!2!2!2! - 2x10!/2!2!2! Please show me how to get the answer, it's important for my midterm, thanks.
14. How many times does "#" print? for(int i = 0; i < 10; ++i) {...
14. How many times does "#" print? for(int i = 0; i < 10; ++i) { if(i == 2 || i==4 || i==6) { continue; } cout << "#"; }
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT