Question

Consider the following C++ code segment: for (int i = 0; i <n; ++i) { for (int j = 0; j <m; ++j) if (i != j) cout << 0; els

Which of the options below gives the correct output if the value of nis 2and the value of mis 3? 1. 100010 2. 011101 3. 10010

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

Answer: 1) 100010

Here I am providing the output for the given code

Proof:

#include <iostream> using namespace std; int main() { for(int i = 0; i < 2; ++i) { //Loop two times for(int j j< 3; ++j){ //

Output

100010

Code

#include <iostream>

using namespace std;

int main()
{
for(int i = 0 ; i < 2;++i){ //loop two times
  
for(int j = 0 ; j < 3; ++j){ //loop six times
  
if(i != j)
cout<<"0";
else
cout<<"1";
}
}
}

Add a comment
Know the answer?
Add Answer to:
Consider the following C++ code segment: for (int i = 0; i <n; ++i) { for...
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

  • 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 time complexity of the following code segment? for (int i = 0; i<n;...

    What is the time complexity of the following code segment? for (int i = 0; i<n; i--) if (a[i] != 0) sum = a[i]; What is the time complexity of the following code segment? for (int i = 0; i<10; i++) if (a[i] != 0) sum += a[i]; What is the time complexity of the following code segment? for (int i = 0; i<n/2; i++) if (a[i] != 0) sum += a[i]; What is the time complexity of the following...

  • (c) int sum(int n) un { int sum=0; for (int i=0; i<n; i++) for(int j=0; j<i/2;...

    (c) int sum(int n) un { int sum=0; for (int i=0; i<n; i++) for(int j=0; j<i/2; j++) for(int k=0; k<min(j,5); k++) { sum=sum+1; } return sum; }

  • (a) Consider the following C++ function: 1 int g(int n) { 2 if (n == 0)...

    (a) Consider the following C++ function: 1 int g(int n) { 2 if (n == 0) return 0; 3 return (n-1 + g(n-1)); 4} (b) Consider the following C++ function: 1 bool Function (const vector <int >& a) { 2 for (int i = 0; i < a. size ()-1; i ++) { 3 for (int j = i +1; j < a. size (); j ++) { 4 if (a[i] == a[j]) return false; 5 6 } 7 return...

  • What is the functionality of the following code? #include #include mainO <stdio.h> <unistd.h> int i,j; j-0:...

    What is the functionality of the following code? #include #include mainO <stdio.h> <unistd.h> int i,j; j-0: printf ("Ready to fork.n) i-fork; if 0) this code.\n"); printf "The child executes for (i-0; i?5; i++) printf("Child j-dn".j); else j-vaito printf("The parent executes this code. Ln" printf ("Parent j-dn",j);

  • 4. Given the following code, int x = 5, n; do{ n = 0; for (int...

    4. Given the following code, int x = 5, n; do{ n = 0; for (int i = 0; i < x; i++) { n = n + x; System.out.println(n); } while (x > 1); a) What will be the value of x after the code segment is executed? Initial value of x 5 b) What is the output of the code segment? c) Explain how the flow of control moves in the given code segment. When explaining, show how...

  • int xyz( char[] X, char[] Y, int m, int n ) { int L[][] = new...

    int xyz( char[] X, char[] Y, int m, int n ) { int L[][] = new int[m+1] [n+1]; for (int i=0; i<=m; i++){ for (int j=0; j<=n; j++){ if (i == 0 Ilj == 0) L[i][j] = 0; else if (x[i-1] == Y[j-1]) L[i][j] = L[i-1][j-1] + 1; else L[i][j] max(L[i-1][j], L[i][j-1]); مه } ...//more code follows Given the code fragment above, select the best descriptive phrase from the list below. Bottom-up. Recursive. Top-down.

  • 20) What is the output of the following segment of C code: int avg(int n, int*...

    20) What is the output of the following segment of C code: int avg(int n, int* a); int main () {             int array[4]={1,0,6,9};             printf("%d", avg(4, array)+ 1);             system("pause");             return 0; } int avg(int n, int* a) { int i, sum=0; for (i=0;i<n;i++) { sum+=a[i]; } return sum/n; } a) 16 b) 5 c) 4 d) 8 21) What is the output of the following segment of C code: int x = 2; int y = 3;...

  • C++ What output does the following program produce? int getValue(int a, int b, int n); int...

    C++ What output does the following program produce? int getValue(int a, int b, int n); int main() cout << getValue(1, 7, 7) << endl; return 0; } // end main int getValue(int a, int b, int n) int returnValue = 0; cout << "Enter: a = " < a << " b = " << b << endl; int c = (a + b)/2; if (C* C <= n) return value = c; else returnValue = getValue(a, C-1, n); cout...

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