ProgrammingModerateAccenture · Cognizant GenC Next
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
String s = "hello world of code"
Integer changes = 0
for (each i from 0 to length(s) - 1)
if ((i == 0 OR s[i - 1] == ' ') AND s[i] is lower-case)
s[i] = upper-case of s[i]
changes = changes + 1
end if
end for
Print s, changes- A. Hello world of code 1
- B. HELLO WORLD OF CODE 16
- C. Hello World Of Code 4
- D. Hello World Of Code 3
Correct answer: C. Hello World Of Code 4
Every letter that starts the string or follows a space is capitalised: h, w, o, c. Output Hello World Of Code 4.
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? (strings are indexed from 0) String s = "ABCABCAB" Integer n = length(s), p = n for…
- What will be the output of the following pseudocode? (strings are indexed from 0; + joins strings) String s = "ABCDEF", r = "" Integer k =…
- What will be the output of the following pseudocode? Integer a[7] = {1, 3, 2, 4, 1, 5, 2}, c = 0 for (each i from 1 to 5) if (a[i] > a[i…
- What will be the output of the following pseudocode? Integer a[5] = {1, 2, 3, 4, 5} Integer odd = 0, even = 1, s = 0, ans = 0 // counts of…
- What will be the output of the following pseudocode? (& is bitwise AND on 32-bit integers) Function pow4(Integer n) return n > 0 AND (n &…
- What will be the output of the following pseudocode? (& is AND, ^ is XOR, << is left shift) Integer x = 7, m = 1 while ((x & m) != 0) x =…