Explanation
In this program, we need to count the words present in the string.
Beauty lies in the eyes of beholder
Total number of words present in the string is 7.
Algorithm
- Define a string.
- To counts the words present in the string, we will iterate through the string and count the spaces present in the string. As each word always ends with a space.
- If a string starts with a space, then we must not count the first space as it is not preceded by a word.
- To count the last word, we will increment the count by 1.
Input:
sentence = "Beauty lies in the eyes of beholder"
Output:
Total number of words in the given string: 7
Python
Output:
C
Output:
JAVA
Output:
C#
Output:
PHP
Output: