The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
+7 votes
613 views
  1. 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;
  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;
    
asked in Algorithms by Veteran (59.7k points)
edited by | 613 views

3 Answers

+8 votes
Best answer
  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

Should be the condition...

answered by Boss (26.1k points)
edited by
+6

one simple solution :

for(i=1; i<n ;++i)

for(j=i; j<n ;++j)

0
@papesh your option B solution is nice
0

@Anu007 Sir, won't it be "<=" ?

+11 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 ;)

answered by Boss (23k points)
+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.
answered by Loyal (8.2k points)

Related questions



Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

44,019 questions
49,545 answers
162,696 comments
65,769 users