String handling operations in a programming language

EasyMedium
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
Question 59
Easy

The LOCATE subroutine returns the 0-based index of the first occurrence of a character in a string.

For example:

  • LOCATE("Cyber Security", "e") would return 3
  • LOCATE("Cyber Security", "S") would return 6

target and phrase are variables used in the algorithm in Figure 1.

Figure 1

phrase ← "Cyber Security"
length ← 14
OUTPUT "Enter the character to find:"
target ← USERINPUT

Complete the pseudo-code statement to find the index of the first occurrence of the contents of target in phrase and store this index in the variable pos.

You must use the LOCATE subroutine in your answer.

pos ← _____

[1]

String handling operations in a programming language Questions

  1. GCSE
  2. /Computer Science
  3. /String handling operations in a programming language