It it simple to find the number of characters in the longest word, but I am having difficulty printing the word with the longest number of characters. Any algorithm suggestions?
Printable View
It it simple to find the number of characters in the longest word, but I am having difficulty printing the word with the longest number of characters. Any algorithm suggestions?
If you already know it's length, and where it starts, then all you need is a for loop.
1) Separate string by words.
2) For each word, check the length of it.
3) If the length of the one you're checking > the longest word you already looked at, then save this one to be the longest word.
4) When you're done searching all of the words, you have the longest word already.