Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

What will be the output of the following code?

+1 vote
asked Jun 13, 2019 by mark (220 points) 1 flag

What will be the output of the following code

#include <iostream>

using namespace std;

int main () {

int n[3][4]={{12,-13,10,4},{9,2,34,2},{12,13,5,6}};

int i,j,v;

v = n[0][0];

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

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

        if (n[i][j]>=v) v=n[i][j];

        }

cout << v <<endl; return 0;

}

1) Error in the code.      2) 34          3) -13            4) 12

7 Answers

0 votes
answered Jun 14, 2019 by aaaaaa
4) 12

it's a linear search algorithm to search for the largest number
0 votes
answered Jun 28, 2019 by Nishant braiwal
second option is correct because initially v will have value equal to 12 but when control will come in 2nd row then value of v will be 34 and as we all know that a variable can hold only one value at a time and no other value in this 2D array is greater than 34 so output i.e value of v will be 34
0 votes
answered Jul 4, 2019 by anonymous
Answer is : 34.
0 votes
answered Jul 4, 2019 by anonymous
1) Error in this code

iostream.h
0 votes
answered Jul 4, 2019 by Screenslaver (140 points)
The answer is :2
0 votes
answered Jul 6, 2019 by anonymous
12 is the output
0 votes
answered Jul 18, 2019 by anonymous
value of v will be 34. as when i counts the value turns 12 but in 2d array the  no gets multiplied by it i.c 3 therefore 34.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...