recategorized by
4,879 views
26 votes
26 votes

The following Pascal program segments finds the largest number in a two-dimensional integer array $A[0\dots n-1, 0\dots n-1]$ using a single loop. Fill up the boxes to complete the program and write against $\fbox{A}, \fbox{B}, \fbox{C} \text{ and } \fbox{D}$ in your answer book Assume that max is a variable to store the largest value and $i, j$ are the indices to the array.

begin
    max:=|A|, i:=0, j:=0;
    while |B| do
    begin
        if A[i, j]>max then max:=A[i, j];
        if |C| then j:=j+1;
        else begin
            j:=0;
            i:=|D|
        end
    end
end
recategorized by

2 Answers

Best answer
42 votes
42 votes

We have to traverse all elements in array. The code is doing this row wise. 


begin
    max:=A[0,0], i:=0, j:=0;
    while (i < n) do
    begin
        if A[i, j]>max then max:=A[i, j];
        if (j < n-1) then j:=j+1;
        else begin
            j:=0;
            i:=i++;
        end
    end
end
selected by
3 votes
3 votes
A:=A[0,0]    B:=(i<n)    C:=(j<n-1)   D:=i++

Related questions

19 votes
19 votes
2 answers
1
Kathleen asked Sep 29, 2014
2,898 views
Prove by the principal of mathematical induction that for any binary tree, in which every non-leaf node has $2$-descendants, the number of leaves in the tree is one more ...
30 votes
30 votes
4 answers
4
Kathleen asked Sep 29, 2014
4,524 views
Let $\left(\{ p,q \},*\right)$ be a semigroup where $p*p=q$. Show that:$p*q=q*p$ and$q*q=q$