one simple solution :

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

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

The Gateway to Computer Science Excellence

First time here? Checkout the FAQ!

x

+8 votes

- 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;

- 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;

+9 votes

Best answer

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

- All categories
- General Aptitude 1.6k
- Engineering Mathematics 7.3k
- Digital Logic 2.9k
- Programming & DS 4.9k
- Algorithms 4.3k
- Theory of Computation 6k
- Compiler Design 2k
- Databases 4.1k
- CO & Architecture 3.4k
- Computer Networks 4.1k
- Non GATE 1.4k
- Others 1.5k
- Admissions 592
- Exam Queries 577
- Tier 1 Placement Questions 23
- Job Queries 72
- Projects 18

49,456 questions

53,658 answers

186,156 comments

70,919 users