Question

In: Computer Science

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 << "#";
}

Solutions

Expert Solution

answer) 7 times # is printed

here i loop runs 10 times.

-->when i=0

if(i == 2 || i==4 || i==6)

{

continue;

}

this if condition is not satisfied so we are not entered into if condtion.so cout<<'#' is printed

-->when i=1

if(i == 2 || i==4 || i==6)

{

continue;

}

this if condition is not satisfied so we are not entered into if condtion.so cout<<'#' is printed

-->when i=2

if(i == 2 || i==4 || i==6)

{

continue;

}

this if condition is satisfied so we are directly go to for loop again with out printing #

-->when i=3

if(i == 2 || i==4 || i==6)

{

continue;

}

this if condition is not satisfied so we are not entered into if condtion.so cout<<'#' is printed

printed

-->when i=4

if(i == 2 || i==4 || i==6)

{

continue;

}

this if condition is satisfied so we are directly go to for loop again with out printing #

-->when i=5

if(i == 2 || i==4 || i==6)

{

continue;

}

this if condition is not satisfied so we are not entered into if condtion.so cout<<'#' is printed

printed

-->when i=6

if(i == 2 || i==4 || i==6)

{

continue;

}

this if condition is satisfied so we are directly go to for loop again with out printing #

-->when i=7

if(i == 2 || i==4 || i==6)

{

continue;

}

this if condition is not satisfied so we are not entered into if condtion.so cout<<'#' is printed

-->when i=8

if(i == 2 || i==4 || i==6)

{

continue;

}

this if condition is not satisfied so we are not entered into if condtion.so cout<<'#' is printed

-->when i=9

if(i == 2 || i==4 || i==6)

{

continue;

}

this if condition is not satisfied so we are not entered into if condtion.so cout<<'#' is printed


Related Solutions

C++ Visual Studios How many times will "!" print? int i = -5 while(-5 <= i...
C++ Visual Studios How many times will "!" print? int i = -5 while(-5 <= i <= 0) { cout << "!"; --i; }
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
#include <iostream> using namespace std; int main() { int even=0,odd=0,sum=0,sum2=0,largest,smallest; int num,i; for ( i=1; i<=10;...
#include <iostream> using namespace std; int main() { int even=0,odd=0,sum=0,sum2=0,largest,smallest; int num,i; for ( i=1; i<=10; i++){ cout << " Enter " << i << " number: "; cin >> num; if ( num%2==0){ even++; sum+=num; } else { odd++; sum2+=num; if(num>largest){ largest = num; } if(num<largest) { smallest = num; } } cout << " The sum of even number is : " << sum << endl; cout << " The total-count of even number is : " <<...
The following is an infinite loop: for (int i = 0; i < 10; i++); System.out.println(i...
The following is an infinite loop: for (int i = 0; i < 10; i++); System.out.println(i + 4); TRUE OR FALSE?
int f2 (int n) j = 0; while (j <n) {for (int i = 0; i...
int f2 (int n) j = 0; while (j <n) {for (int i = 0; i <n; ++ i) {cout << "j =" + j; j = j + 5; }}
(C++)Change the following loop to a while loop: int i; for (i=0; i<10; i++) {    ...
(C++)Change the following loop to a while loop: int i; for (i=0; i<10; i++) {     cout<<i<<endl; }
public void printQueue(DoublyLinkedQueue<Integer> Q){ int len = Q.size(); int k = 0; for (int i=0; i...
public void printQueue(DoublyLinkedQueue<Integer> Q){ int len = Q.size(); int k = 0; for (int i=0; i < len; ++i){ k = Q.dequeue(); Q.enqueue(k);    System.out.println(Q.dequeue()); } } What is the complexity of this code? Select one: a. O(N), N = k b. Q(1) c. Q(N2), N = Q.size() d. O(M), M = Q.size() e. None of the alternatives is correct. which one?
In Java, we typically iterate over a sequence of integers as follows: for (int i=0; i<10;...
In Java, we typically iterate over a sequence of integers as follows: for (int i=0; i<10; i = i + 2) { ... } Suppose we use a version of Java that only supports for-each loops, i.e. it only allows you to iterate through the elements of an Iterable In order to still be able to iterate over a sequence of numbers, you need to create such an Iterable, which we will call Range. Modify the class Range.java so that...
how many times does a reaction speed up if the T rises from 10*C to 40*...
how many times does a reaction speed up if the T rises from 10*C to 40* C?
Show the output of the following code segment. int count=0;                         for (int i=2; i <=...
Show the output of the following code segment. int count=0;                         for (int i=2; i <= 4; i++ ) {                                     StdOut.println(i);                                     for (int j=1; j <3; j++) {                                                 count++;                                                 StdOut.println(i +" " + j +" "+ count);                                     }                         } count i j I print 0 2 1 3 1 1 1 2 3 2 2 3 3 3 3 4 3 Show the output of the function call statements shown.             double x =...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT