ProgrammingHardCognizant GenC Next · Accenture
What will be the output of the following pseudocode? (code(c) gives a letter's character code)
What will be the output of the following pseudocode? (code(c) gives a letter's character code)
String s = "PROGRAMMING", r = ""
Boolean seen[26] = all false
for (each i from 0 to length(s) - 1)
if (not seen[code(s[i]) - code('A')])
r = r + s[i]
seen[code(s[i]) - code('A')] = true
end if
end for
Print r, length(r)- A. PROGAMIN 7
- B. POAIN 5
- C. PROGAMIN 8
- D. PRGAMIN 7
Correct answer: C. PROGAMIN 8
Each letter is kept only the first time it appears: P, R, O, G, then R skipped, A, M, M skipped, I, N, G skipped. r = PROGAMIN with 8 letters.
Practise more Pseudocode and Code Tracing questionsPseudocode and Code Tracing: notes and key points
More Pseudocode and Code Tracing questions
- What will be the output of the following pseudocode? String s = " the quick brown fox " Integer words = 0 Boolean inWord = false for (each…
- What will be the output of the following pseudocode? Integer val[7] = {1000, 500, 100, 50, 10, 5, 1} String sym[7] = {"M", "D", "C", "L"…
- What will be the output of the following pseudocode? (code(c) gives a character's code; 'A' to 'Z' have consecutive codes) String a =…
- What will be the output of the following pseudocode? (Strings are indexed from 0) String s = "BANANAS" Integer best = 1, l, r, n = 7 for…
- What will be the output of the following pseudocode? (& is AND, | is OR, << and >> are shifts; 15 = 0000 1111 and 240 = 1111 0000) Integer…
- What will be the output of the following pseudocode? Integer a[7] = {4, 1, 2, 1, 2, 5, 4} Integer x = 0 for (each i from 0 to 6) x = x ^…