recategorized by
2,932 views
16 votes
16 votes
  1. Consider the following Pascal function where $A$ and $B$ are non-zero positive integers. What is the value of $\text{GET}(3, 2)$?
    function GET(A,B:integer): integer;
    begin
        if B=0 then
            GET:= 1
        else if A < B then
            GET:= 0
        else
            GET:= GET(A-1, B) + GET(A-1, B-1)
    end;
  2. The Pascal procedure given for computing the transpose of an $N \times N, (N>1)$ matrix $A$ of integers has an error. Find the error and correct it. Assume that the following declaration are made in the main program
    const
        MAXSIZE=20;
    type
        INTARR=array [1..MAXSIZE,1..MAXSIZE] of integer;
    Procedure TRANSPOSE (var A: INTARR; N : integer);
    var
        I, J, TMP: integer;
    begin
        for I:=1 to N – 1 do
        for J:=1 to N do
        begin
            TMP:= A[I, J];
            A[I, J]:= A[J, I];
            A[J, I]:= TMP
        end
    end;
    
recategorized by

3 Answers

Best answer
13 votes
13 votes
  1. $3$
  2.  
begin
    for I:=2 to N do
    for J:=1 to ( I-1) do
    begin
        TMP:= A[I, J];
        A[I, J]:= A[J, I];
        A[J, I]:= TMP
    end
end

Should be the condition.

edited by
24 votes
24 votes

Plz refer below img.

Q.B:->Error is there bcz we are swapping content of cells of matrix two times whose overall effect is Nothing .

Correction is only J=I+1 instead of J=1 .

By doing above change in code we are swapping only Upper triangular part with Lower triangular which is nothing but Transpose of matrix.

Everything else is All is Well ;)

2 votes
2 votes
ans for A is 3.

ans for B is:

outer for loop should run for 1 to n/2, if it run for n-1 times then it will again put the transposed elements at its original place.

Related questions

11 votes
11 votes
3 answers
1
21 votes
21 votes
1 answer
2
Kathleen asked Oct 8, 2014
3,904 views
In the following Pascal program segment, what is the value of X after the execution of the program segment?X := -10; Y := 20; If X Y then if X < 0 then X := abs(X) else ...
14 votes
14 votes
1 answer
4