cmi-entrance 2024 Q12

cmi-entrance · India · mscds Not Maths
12. In the following code, A is an array indexed from 0 whose elements are all positive integers, and n is the number of elements in A . It is given that n is at least 2 . The operator $*$ denotes multiplication.
\begin{verbatim} function foo(A,n) { if A[0] > A[1] { first = A[0]; second = A[1]; } else { first = A[1]; second = A[0]; } for i from 2 to (n-1) { if A[i] > second { if A[i] > first { second = first; first = A[i]; } else { second = A[i]; } } } return(first * second); } \end{verbatim}
If $\mathrm { A } = [ 15,7,16,12,17,14,16,4,13,12 ]$, what will $\mathrm { f } _ { \mathrm { o } } \circ ( \mathrm { A } , 10 )$ return?
(a) 28
(b) 144
(c) 180
(d) 272
12. In the following code, A is an array indexed from 0 whose elements are all positive integers, and n is the number of elements in A . It is given that n is at least 2 . The operator $*$ denotes multiplication.

\begin{verbatim}
function foo(A,n) {
    if A[0] > A[1] {
        first = A[0];
        second = A[1];
    } else {
        first = A[1];
        second = A[0];
    }
    for i from 2 to (n-1) {
        if A[i] > second {
            if A[i] > first {
                second = first;
                first = A[i];
            } else {
                second = A[i];
            }
        }
    }
    return(first * second);
}
\end{verbatim}

If $\mathrm { A } = [ 15,7,16,12,17,14,16,4,13,12 ]$, what will $\mathrm { f } _ { \mathrm { o } } \circ ( \mathrm { A } , 10 )$ return?\\
(a) 28\\
(b) 144\\
(c) 180\\
(d) 272\\