Question

Consider the following code segment, what is the output? //you please explain your answer with all...

Consider the following code segment, what is the output?
//you please explain your answer with all the steps??
          
          int j, k;
          for (k=0;k<10; k++)
          {
             for (j=0; j<5;j++)
             cout << "*";
          }
          cout << endl;
0 0
Add a comment Improve this question Transcribed image text
Answer #1

// Screenshot of the code

Untitled1 Dev-C++5.11 X AStyle Window Help File Edit Search View Project Execute Tools 品口国品 TDM-GCC 4.9.2 64-bit Releas globa
// Sample output

C:AUsers\Lenovo\Desktop\demo.exe Process exited after 0.06477 seconds with return value 0 Press any key to cont inue X
// code to copy

#include <iostream>

using namespace std;

int main()
{   
int j, k;
// outer for loop
   for (k=0;k<10; k++)
   {
       // inner for loop
       for (j=0; j<5;j++)
       cout << "*";
   }
   cout << endl;
return 0;
}

Explanation:

here output prints as * for 50 times because for

per each iteration of outer for loop, the inner for loop executes 5 times j starts from 0 to 5 by printing * for each iteration.

After 1st iteration of outer for loop inner for loop executes and prints * for 5 times as *****

after 2nd iteration of outer for loop ,the inner for loop adds another 5* so output **********

after 3rd iteration of outer for loop ,the inner for loop adds another 5* so output ***************

-------------------------------------------------------------------------------------------------------------------------

after 10th iteration of outer for loop ,the inner for loop adds another 5* so output ************************************************************

Here

for (k=0;k<10; k++)  is outer for loop

for (j=0; j<5;j++) is an inner for loop
      

Add a comment
Know the answer?
Add Answer to:
Consider the following code segment, what is the output? //you please explain your answer with all...
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
  • Part #2 Trace and show your steps and the output of the following code segment const...

    Part #2 Trace and show your steps and the output of the following code segment const int TEN = 10; int a(TEN), n = 354, num, c = 0; num = n; a[C++] = num % TEN; num = num/TEN; } while (num); cout << "The number" <<n<<" is now: for (int k = -1;k >= 0; k--) cout << a[k]; cout << endl; Trace and show the content of the arrays A and B int A[7] = {66, 55,...

  • 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 +...

  • 12. What is the output of the following C++ code? int x; int y; int *p...

    12. What is the output of the following C++ code? int x; int y; int *p = &x; int *q = &y; *p = 35; *q = 98; *p = *q; cout << x << " " << y << endl; cout << *p << " " << *q << endl; 13. What is the output of the following C++ code? int x; int y; int *p = &x; int *q = &y; x = 35; y = 46; p...

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

  • 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.) for (int k = 2; k < 5; k++)                    {       for (int j = 3; j < 6; j++)      cout << setw(4) << (k + j) << " ";       cout << endl;    }

  • Hello, please EXPLAIN how you got your answer. Thank you! int x = 1 int j;...

    Hello, please EXPLAIN how you got your answer. Thank you! int x = 1 int j; for (j=0; j <=2  ; j++) x = x * j ; cout << x << endl; What is the output of the C++ code above? Answer: A) 0 B) 1 C) 2 D) 3

  • c++ In the following segment of the code, what will be the output if opening of...

    c++ In the following segment of the code, what will be the output if opening of the file is not successful? ifstream infile; try{ infile.open("test.txt"); if(!infile) throw -1; else cout << "successful" << endl; } catch(const char* msg) { cout << msg << " unsuccessful" << endl; } catch(int i) { cout << i < was returned, unsuccessful" <<endl; #8 WA w

  • points): Show the output of the code below as it would appear on the monitor. int...

    points): Show the output of the code below as it would appear on the monitor. int main cout <<" <<endl: int wildcat 2: while (wildcat > 5) cout << wildcat <<endl; wildcat++ cout <K*<< endl; int jayhavk 5i do cout << jayhawk <s endl: while (jayhawk0) cout <<*" << endl; int wolverine l: while (wolverine 0 &&wolverine < 10) cout << wolverine <<endl: wolverine2: cout <<" <<endl: for (int zag-4; zag>0; zag_) cout <<****" << endl; for (int i-10; i<-30;...

  • Please, explain your answer clearly (step-by-step) What output does this loop generate? int j = 1;...

    Please, explain your answer clearly (step-by-step) What output does this loop generate? int j = 1; do { int value = j * 2; j++; cout << value << ", "; } while (j <= 5); What is the output of the following code snippet? int my_fun (int A[], int size) {   int result = 0;   for (int i = 0; i < size; i++)   {    result = result + A[i];   }   return result; } int main() {   int...

  • 18 C++ 1. What is the output of the following program segment? int y-22: while ((y...

    18 C++ 1. What is the output of the following program segment? int y-22: while ((y 3) != 0) cout << y<< "": y=y-2; The output is 2. Suppose that the input is 100, 20,-8, 50, 20. What is the output of the following C++ code? int sum0 int num: int j cin >> num: if (num < 0) continue зит зит + num; cout<< sum << endl; The output is

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
ADVERTISEMENT