UNIT
3 STRINGS
IT 105 Computer Programming 2
Programs using String Functions
IT 105 Computer Programming 2
Program 1
A program using string functions that accepts two words with equal
number of characters.
IT 105 Computer Programming 2
Program 1 - Solution A
getting the length of two strings ,
storing the results on variable x
and y
IT 105 Computer Programming 2
Program 1 - Solution B
testing directly if two strings are
equal in length
IT 105 Computer Programming 2
Program 2
A program using string functions that accepts word ending in y.
IT 105 Computer Programming 2
Program 2 – Solution A
Testing if the last index contains
character ‘y’ . The last index is
dependent on string length
IT 105 Computer Programming 2
Program 2 – Solution B
getting the last index of the string
variable word
IT 105 Computer Programming 2
Program 2 – Solution C
Testing if the first character of the
reversed string is ‘y’
IT 105 Computer Programming 2
Program 3
A program using string functions that produces a string that
contains the full name from the first name and last name entered
by the user.
IT 105 Computer Programming 2
Program 3 Solution
IT 105 Computer Programming 2
Program 4
A program using string function that determines if the input word
is a palindrome. A palindrome is a word that produces the same
word when it is reversed.
For example,
madam, pop, mom and dad are palindromes
IT 105 Computer Programming 2
Program 4 – Solution A
Setting the letters to
uniform case
Creating a duplicate copy
of the inputted string
before reversing
Comparing the inputted
word and its reversed form
.
IT 105 Computer Programming 2
Program 4 – Solution B
Instead of converting the
string to a uniform case,
strcmpi is used to ignore
string case
IT 105 Computer Programming 2
Program 4 – Solution C
IT 105 Computer Programming 2