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 firstname.lastname@example.org. 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.
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- 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 Encrypted word
- Program to find the kth character after decrypting a string
- Program to find all match of a regex in a string
- Program to find Smallest and Largest Word in a String
- Program to find the XOR of ASCII values of characters in a string
- Program to find remainder when large number is divided by r
- Python program to find uncommon words from two Strings
- Program to find remainder when large number is divided by 11
- 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
- C program to find and replace a word in a File by another given word
- Program to print last N lines | Set-2