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 : " <<...
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?
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?
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/*
#include #include #include int main(void) { int feof(FILE *stdin); int i, num; int binary[10]; char input[10];...
#include #include #include int main(void) { int feof(FILE *stdin); int i, num; int binary[10]; char input[10]; printf("Starting the CPSC 1011 Decimal to Binary Converter!\n"); while(1) {    i=0;    printf("\nPlease enter a positive whole number (or EOF to quit): ");    scanf("%s", input); // user inputs value as a string for separate values    if(strcmp(input,"")==0) {        printf("\n\tThank you for using the CPSC 1011 Decimal to Binary Generator.\nGoodbye!\n\n");    return(0); } num=atoi(input); if (num<=0) {    printf("\n\tSorry, that was...
unsigned u =10; int i = -42; cout << i+i <<endl; cout << u+i<<endl;//if int take...
unsigned u =10; int i = -42; cout << i+i <<endl; cout << u+i<<endl;//if int take 32 bit, output 4294967264 I know when unsigned and singed operate together, they need to be converted, but why is the answer 4294967264? What does it have to do with int .…… 32 bit
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT