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.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Python | Print the initials of a name with last name in full
- Program to print the initials of a name with the surname
- Check if a string is the typed name of the given name
- Find Excel column name from a given column number
- How to validate a domain name using Regular Expression
- Program to find the largest and smallest ASCII valued characters in a string
- Program to find Smallest and Largest Word in a String
- Program to find remainder when large number is divided by 11
- Program to find all match of a regex in a string
- Program to find the product 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 the kth character after decrypting a string
- Program to find the Encrypted word
- Program to find the XOR of ASCII values of characters in a string
- C program to find and replace a word in a File by another given word
- Program to find Greatest Common Divisor (GCD) of N strings
- C program to find the frequency of characters in a string
- Program to find second most frequent character
- Write a program to print all permutations of a given string