(a) Consider the following Pascal function where A and B are non-zero positive…

PYQ GATE 1995Modified — slightly modified from the official paper; see the solution

(a) Consider the following Pascal function where A and B are non-zero positive integers. What is the value of 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 ;

(b) The Pascal procedure given for computing the transpose of an N × 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:=I+1 to N do

begin

TMP:= A[I,J];

A[I,J]:=A[J,I];

A[J,I]:=TMP

end

end;

Sign up free to check your answer

Sign up free

Explore the full course: Data Structures

Loading lesson…