What is the output produced by the following program, when the input is…

PYQ GATE 1989

What is the output produced by the following program, when the input is "HTGATE"

Function what (s:string): string;
var n:integer;
begin
     n = s.length
     if n <= 1
     then what := s
     else what :=contact (what (substring (s, 2, n)), s.C [1])
end;

Note

(i) type string=record length:integer; C:array[1..100] of char end

(ii) Substring (s, i, j): this yields the string made up of the ith through jth characters in s; for appropriately defined i and j.

(iii) Contact (s1, s2): this function yields a string of length s1-length + s2-length obtained by concatenating s1 with s2 such that s1 precedes s2.

Attempted by 1 students.

Sign up free to check your answer

Sign up free

Explore the full course: Algorithms

Loading lesson…