Given a string name, we have to find the initials of the name
Input : prabhat kumar singh Output : P K S We take the first letter of all words and print in capital letter. Input : Jude Law Output : J L Input : abhishek kumar singh Output : A K S
1) Print first character in capital.
2) Traverse rest of the string and print every character after space in capital letter.
P K S
Another possible solution is given as follows:
P K S
The complexity of this code will be less than O(w) where w is number of words in sentence, which can be little better than number of characters in String.
This code is contributed by Anuj Khasgiwala
We can also use strtok() function in C/C++ to achieve this.
This article is contributed by Prabhat kumar singh. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Program to print the initials of a name with the surname
- Python | Print the initials of a name with last name in full
- Program to find second most frequent character
- Program to find the kth character after decrypting a string
- Program to find all match of a regex in a string
- Program to find remainder when large number is divided by 11
- Python program to find uncommon words from two Strings
- Program to find remainder when large number is divided by r
- Program to find Smallest and Largest Word in a String
- Program to find the product of ASCII values of characters in a string
- Program to find the largest and smallest ASCII valued characters in a string
- Program to check for ISBN
- Program to check if two strings are same or not
- Program to print last N lines | Set-2
- Program to validate an IP address