Question

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)

  1. What output does this loop generate?

int j = 1;

do

{

int value = j * 2;

j++;

cout << value << ", ";

}

while (j <= 5);

  1. 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 myarr[10] = { 5, 6, 10, 1, 2, 4, 8, 1, 2, 1 };

  for (int i = 0; i < 3; i++)

  {

   cout << my_fun(myarr, i);

  }

}

    1. No output
    2. 0511
    3. 056
    4. 000
  1. 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 myarr[10] = { 2, 4, 10, 1, 2, 4, 8, 1, 2, 1 };

  for (int i = 0; i < 3; i++)

  {

   cout << my_fun(myarr, myarr[i]);

  }

}

  1. 026
  2. 6435
  3. 61735
  4. 600

Consider the following code snippet:

int cnt = 0;

int numarray[2][3];

for (int i = 0; i < 3; i++)

{

  for (int j = 0; j < 2; j++)

  {

    numarray[j][i] = cnt;

    cnt++;

  }

}

  1. What is the value of numarray[1][2] after the code snippet is executed?
    1. 2
    2. 5
    3. 3
    4. 4

5) Consider the following code snippet:

int cnt = 0;

int myarray[4][5];

for (int i = 0; i < 5; i++)

{

  for (int j = 0; j < 4; j++)

  {

    myarray[j][i] = cnt;

    cnt++;

  }

}

What is the value of myarray[1][2] after the code snippet is executed?

  1. 8
  2. 9
  3. 19
  4. 11
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please do understand my concern, as per Chegg guidelines we are supposed to answer the first question if there is more than one question in a post, your downvote effects my career a lot, if I get a downvote for a wrong answer or incomplete answer I will accept it. Please give a positive rating

Add a comment
Know the answer?
Add Answer to:
Please, explain your answer clearly (step-by-step) What output does this loop generate? int j = 1;...
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
  • Please explain clearly your answers (step by step): 1) What is the output of the following...

    Please explain clearly your answers (step by step): 1) 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 myarr[10] = { 5, 6, 10, 1, 2, 4, 8, 1, 2, 1 }; for (int i = 0; i < 3; i++) {   cout << my_fun(myarr, i);...

  • Please, explain clearly each line of code with your answers. Question 1 Consider the following code...

    Please, explain clearly each line of code with your answers. Question 1 Consider the following code snippet: int ctr = 0; int myarray[3]; for (int i = 0; i < 3; i++) { myarray[i] = ctr; ctr = ctr + i; } cout << myarray[2]; What is the output of the code snippet? Question 2 Consider the following code snippet: int cnt = 0; int numarray[2][3]; for (int i = 0; i < 3; i++) {   for (int j =...

  • QUESTION 9 What will be the output of following code snippet? int a[3] = {1, 2,...

    QUESTION 9 What will be the output of following code snippet? int a[3] = {1, 2, 3};         int *p = a;         int **r = &p;         printf("%p %p", *r, a); A. Different memory addresses printed B. 1 2 C. Same memory address printed twice D. 1 1 2 points    QUESTION 10 What will be the output of following code snippet? int arr[4] = {1, 2, 3, 4};         int *p;         p = arr + 3;         *p = 5;         printf("%d\n", arr[3]); A....

  • QUESTION 1 What is the output of the following code snippet? int main() { bool attendance...

    QUESTION 1 What is the output of the following code snippet? int main() { bool attendance = false; string str = "Unknown"; attendance = !(attendance); if (!attendance) { str = "False"; } if (attendance) { attendance = false; } if (attendance) { str = "True"; } else { str = "Maybe"; } cout << str << endl; return 0; } False True Unknown Maybe QUESTION 2 What is the output of the following code snippet? #include <iostream> #include <string> using...

  • 1)What is the output of the following code: int i = 10; do { cout <<...

    1)What is the output of the following code: int i = 10; do { cout << i; i++; } while (i < 5); cout << "-done"; 2)What is the output of the following code (note there are no endl's, all output is on single line)? for (int i = 1; i <= 3; i++) {    cout << '(';    for (int j = 0; j < (i*2); j++)        cout << 'x';    cout << ')'; }

  • howthe   output   of   the   following   4   program segments (a)    const int SIZE=8;    int values[SIZE]...

    howthe   output   of   the   following   4   program segments (a)    const int SIZE=8;    int values[SIZE] = {10, 10, 14, 16, 6, 25, 5, 8};    int index;    index=0;    res = values[index];    for (int j=1; j<SIZE; j++)    {        if (values[j] > res)        {            res = values[j];            index = j;        cout << index << res << endl;        }    }    cout <<...

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

  • 1.The following statement gets an element from position 4 in an array named myArray: x =...

    1.The following statement gets an element from position 4 in an array named myArray: x = myArray[4]; What is the equivalent operation using an array list named list.? A x = list.get(); B x = list.get(4); C x = list.get[4]; D x = list[4]; 2.Consider the following code snippet: ArrayList<Integer> num1 = new ArrayList<Integer>(); int data; Scanner in = new Scanner(System.in); for (int i = 0; i < 5; i++) { data = in.nextInt(); num1.add(data); if (data == 0 &&...

  • #include <iostream> #include <string> using std::string; using std::cout; using std::endl; void testAnswer(string testname, int answer, int...

    #include <iostream> #include <string> using std::string; using std::cout; using std::endl; void testAnswer(string testname, int answer, int expected) { if (answer == expected) cout << "PASSED: " << testname << " expected and returned " << answer << "\n"; else cout << "FAILED: " << testname << " returned " << answer << " but expected " << expected << "\n"; } // Implement printArray here void printArray(int array[],int b) { for(int i = 0; i<b;i++) { std::cout<< array[i] << "...

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

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