![]() |
VOOZH | about |
Write a program to count the number of characters in a word.
Examples:
Input: Word: "programming"
Output: 11Input: Word: "hello"
Output: 5
Approach: To solve the problem, follow the below idea:
To count the number of characters in a word, maintain a variable to count all the characters. Iterate through each character in the word and increment the counter for every character.
Step-by-step algorithm:
Below is the implementation of the algorithm:
Number of characters: 11
Time Complexity: O(N), where N is the length of the word.
Auxiliary Space: O(1)