Question

(C++) Given the following code,

for (int y 0; y 〈 4; y++) for (int z 0: z 〈 5; z++) cout << x * y * z くく endl;

please help me answer these three parts and please explain as simply as you can.

1.) How many iterations of the innermost loop? (please show calculation)

2.) What is the largest output?

3.) How many zeroes at the start? (please show/explain calculation)

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

ANSWER:-

total = 60

for first loop x=0 and second loop y=0 then third loop exicute total 5 times

again  for first loop x=0 and second loop y=1 then third loop exicute total 5 times

for first loop x=0 and second loop y=2 then third loop exicute total 5 times

for first loop x=0 and second loop y=3 then third loop exicute total 5 times

after x=0 total iteration 20 so same for x=1 and x=2

20+20+20=60

Question (2):- largest output = 24

Question (3):- 26  

for first loop x=0 and second loop y=0 then third loop exicute total 5 times and give 0

for first loop x=0 and second loop y=1 then third loop exicute total 5 times and give 0

for first loop x=0 and second loop y=2 then third loop exicute total 5 times and give 0

for first loop x=0 and second loop y=3 then third loop exicute total 5 times and give 0

so after exicution of x=0 total zero 20

for first loop x=1 and second loop y=0 then loop exicute total 5 times and give 0

for first loop x=1 and second loop y=1 then loop exicute total 5 times and give only first time 0 for z=0

so total 20+5+1=26

Add a comment
Know the answer?
Add Answer to:
(C++) Given the following code, please help me answer these three parts and please explain as...
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
  • C++ 5.How many times will the following loop run? int i=5; while (i19) 6 . What...

    C++ 5.How many times will the following loop run? int i=5; while (i19) 6 . What is the output of the following code snippet? int time 1; int year2 int rate = 1; int principal = 5; int interest-0 cout <<i < endl while (year< 5) interest (principal * time rate) /1 ; cout << interest << endl; year++

  • 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;

  • In the code given below, how many times the cout statement is executed? for (int x...

    In the code given below, how many times the cout statement is executed? for (int x = 0; x< 10; x++) for (int y=0; y < 10; y++) for (int z = 0; z <=10; z++) cout << X+y+z;

  • /// c ++ question plz help me fix this not a new code and explain to...

    /// c ++ question plz help me fix this not a new code and explain to me plz /// Write a function to verify the format of an email address: bool VeryifyEmail(char email[ ]); Do NOT parse the email array once character at a time. Use cstring functions to do most of the work. Take a look at the available cstring and string class functions on cplusplus website. Use a two dimensional array to store the acceptable top domain names:...

  • How many Iterations will this while loop perform? int ico), j(10); cout << "i = "...

    How many Iterations will this while loop perform? int ico), j(10); cout << "i = " << i << endl; cout << "j = " << j << endl; while (i > j) { cout << "j-" « j << endl; j += 2; cout << "i = " << i << endl; } cout << "i = << i << endl; cout << "j = " << j << endl; 5 6 C 8 10 Infinite times Does the...

  • Can you help me explain how fork, getpid(), cout work in this code? I got a...

    Can you help me explain how fork, getpid(), cout work in this code? I got a quiz today which asked me how many times cout and fork() is executed. #include <iostream> #include <unistd.h> using namespace std; int main ( int argc, char *argv [] ) { int pid; cout << getpid()<<endl; pid = fork(); if (pid == 0) { cout << getpid() <<endl; fork(); cout << getpid()<<endl; fork(); cout << getpid()<<endl; } return 0; }

  • Language is C++ Complete the following Review Questions: 1. This is a control structure that repeats...

    Language is C++ Complete the following Review Questions: 1. This is a control structure that repeats a group of statements in a program? a. loop b. switch c. main() function d. compiler 2. In the expression number++,the ++operator is in what mode? a. Prefix b. Pretest c. Postfix d. Posttest 3.This is a variable that controls the number of iterations performed by a loop. a. Loop control variable b. Accumulator c. Iteration register variable d. Repetition meter 4. The do-whileloop...

  • what is the output of the following code segment? C++ g. int arr[3][4]; for (int i...

    what is the output of the following code segment? C++ g. int arr[3][4]; for (int i = 0; i < 3; i++) for (int j = 0; j < 4; j++) arr[i][j] =i*4 + j; for (int i = 0; i < 3; i++) for (int j = 0; j < 4; j++) cout << arr[i][j] << " "; h. int next(int & x) { x= x + 1; return (x + 1); int main() { int y = 10;...

  • How can I fix that ? Can you please explain clearly ? main.cpp 2 3 using...

    How can I fix that ? Can you please explain clearly ? main.cpp 2 3 using namespace 4. 5 int main() std; unsigned int x = 0b01101100; 8 9 10 12 13 14 15 16 17 18 19 20 21 unsigned int z = 0x12345678; unsigned int e 0x7; unsigned int w = 0x87654321; unsigned int =0x123; int 1; int 92; int Q3; int Q4; Q1=x&y; cout << bitset<8> (Q1) << endl; Q2=-(x| y); cout << bitset<8>(Q2) << endl; Q3=(z...

  • What are the errors in the following code? My professor gave us this prewritten code and...

    What are the errors in the following code? My professor gave us this prewritten code and asked us to find the errors in it so that it can run properly #include <cstdlib> #include <ctime> #include <iostream> using namespace std; // input: integer // output: none // adds five to the given parameter void addFive( int x ) { x += 5; } // input: none // output: a random number int generateRandomNumber() { srand( time(0) ); return rand() % 100;...

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