Question

] Look at the following code: for(i=1; i<=12;i++) {      for(j=1;j<=(i/3); j++)      {          cout<<j<<"...

  1. ] Look at the following code:

for(i=1; i<=12;i++)

{

     for(j=1;j<=(i/3); j++)

     {

         cout<<j<<" ";

     }

     cout<<endl;

}

Mention the output. Also put the value of i and j in each line

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

The output for the code is:

i = 3, j = 1

i = 4, j = 1

i = 5, j = 1

i = 6, j = 1
i = 6, j = 2

i = 7, j = 1
i = 7, j = 2

i = 8, j = 1
i = 8, j = 2

i = 9, j = 1
i = 9, j = 2
i = 9, j = 3

i = 10, j = 1
i = 10, j = 2
i = 10, j = 3

i = 11, j = 1
i = 11, j = 2
i = 11, j = 3

i = 12, j = 1
i = 12, j = 2
i = 12, j = 3
i = 12, j = 4

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

//The code executed:

#include <iostream>

using namespace std;

int main()
{
   int i, j;
   for(i=1; i<=12;i++)
   {
       for(j=1;j<=(i/3); j++)
       {
           cout<<" i = " << i << ", j = " << j<< endl;
       }
       cout<<endl;
   }
   return 0;
}

--------------------Screenshots--------

{ main.cpp 1 #include <iostream> 2 3 using namespace std; 4 5 int main() 6 7 int i, j; 8 for(i=1; i<=12; i++) 9 { 10 for(j=1;

} ./main i = 3, j = 1 i = 4, j = 1 i = 5, j = 1 i = 6, j = 1 i = 6, j = 2 i = i = 7, j = 1 7, j = 2 i = 8, j = 1 i = 8, j = 2

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

The outer loop runs from i = 1 to i = 12

For each i, The inner loop runs for values of j = 1 to j = (i/3)

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

I hope this helps you,

Please rate this answer if it helped you,

Thanks for the opportunity

Add a comment
Know the answer?
Add Answer to:
] Look at the following code: for(i=1; i<=12;i++) {      for(j=1;j<=(i/3); j++)      {          cout<<j<<"...
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
  • Consider the following C++ code segment: if (i j) cout << "1"; else if ((i &j)...

    Consider the following C++ code segment: if (i j) cout << "1"; else if ((i &j) < 3) cout << "2"; else if (i < (j-1)) cout << "3"; else cout << "4"; cout << "5"; If the value of iis 5and the value of jis 6, which of the options below gives the correct output? 1. 25 2. 35 3. 15 4. 45

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

  • 12) 8 pts. Find the errors in the following code fragment and correct them. #i nclude...

    12) 8 pts. Find the errors in the following code fragment and correct them. #i nclude <iostream> using namespace std; double fudge (double s) f return s 2.3; int mainO cout >> "Your original estimate" double estimate; cin >> estimate; cout << endl; for (int 1 = 0;1c3;i++); cout << "EStimate' < fudge(estimate) <<endl Hint: There are 4 syntax errors. There is one error that is syntactically correct but causes the output to not be what you would expect. Once...

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

  • #include <iostream> #include <climits> Using namespace std; Intmain() { Int I; Int j; Cout << “For...

    #include <iostream> #include <climits> Using namespace std; Intmain() { Int I; Int j; Cout << “For this compiler: “ << endl; Cout << “integers are: “ << sizeof(int) << “bytes” << endl; Cout << “largest integers is “ <<INT_MAX << endl; Cout << “smallest integers is “ <<INT_MIN << endl; Cout << “Input two integers values “ << endl; Cin >> i >> j; Cout << endl << “You entered the following values: “ << endl; Cout << “integer “...

  • The following function prints a natural number sequence across the diagonal of an n by n...

    The following function prints a natural number sequence across the diagonal of an n by n square matrix. Debug the code to fix all the compilation and run-time errors, so that the code generates the desired output. For instance, when the num value passed to the function is 5, the output would look like the following. 1**** *2*** **3** ***4* ****5 void naturalDiagonal(int num); for (int i=0; i < num - 1; i++) { for (int j=1; j <= number;...

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

  • 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 many 'X's will be output? while (i <=3){ k=1: while (k <- i) { cout...

    How many 'X's will be output? while (i <=3){ k=1: while (k <- i) { cout << "x"; cout << endl; ++i;)

  • I need help fixing my code: In C++ *************** 1) I want to sum the digits...

    I need help fixing my code: In C++ *************** 1) I want to sum the digits of an n*n matrix 2) find the average I have completed the rest ****Do not use C++ standard library. You must use pointers and pointer arithmetic to represent the matrix and to navigate through it. MY CODE: (I have indicated at which point I need help) #include <iostream> using namespace std; void swap(int *xp, int *yp) { int temp = *xp; *xp = *yp;...

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