C++ Exercises: Create a new string taking the first character from a given string and the last character from another given string
First and Last Character from Two Strings
Write a C++ program to create a string taking the first character from a string and the last character from another given string. If the length of any given string is 0, use '#' as its missing character.
Sample Solution:
C++ Code :
Sample Output:
Hi PP JS C#
Visual Presentation:

Flowchart:

For more Practice: Solve these Related Problems:
- Write a C++ program that takes two strings and forms a new string by concatenating the first character of the first string and the last character of the second string; use '#' if any string is empty.
- Write a C++ program to read two inputs and output a combined string consisting of the first letter of the first input and the final letter of the second input, substituting '#' for any missing character.
- Write a C++ program that creates a string by merging the first character from one string and the last character from another; if either string is empty, use '#' in its place.
- Write a C++ program to combine the edge characters of two input strings into a new string, ensuring that empty inputs are replaced by '#'.
C++ Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a C++ program to create a new string of length 2, using first two characters of a given string. If the given string length is less than 2 use '#' as missing characters.
Next: Write a C++ program to create a new string from a given string after swapping last two characters.
What is the difficulty level of this exercise?