C#: Calculate the average word length in a string
Write a C# Sharp program to calculate the average word length in a given string. Round the average length up to two decimal places.
Note: Ignore punctuation.
Sample Data:
("CPP Exercises." -> 6
("C# syntax is highly expressive, yet it is also simple and easy to learn.") -> 4
(“C# is an elegant and type-safe object-oriented language") -> 5.62
Sample Solution-1:
C# Sharp Code:
Sample Output:
Original string: CPP Exercises. The average word length in the said string: 6 Original string: C# syntax is highly expressive, yet it is also simple and easy to learn. The average word length in the said string: 4 Original string: C# is an elegant and type-safe object-oriented language The average word length in the said string: 5.62
Flowchart:

Sample Solution-2:
C# Sharp Code:
Sample Output:
Original string: CPP Exercises. The average word length in the said string: 6 Original string: C# syntax is highly expressive, yet it is also simple and easy to learn. The average word length in the said string: 4 Original string: C# is an elegant and type-safe object-oriented language The average word length in the said string: 5.62
Flowchart:

C# Sharp Code Editor:
Improve this sample solution and post your code through Disqus
Previous C# Sharp Exercise: Check a string is Valid Hex Code or not.
Next C# Sharp Exercise: Possible Palindromes from string of characters.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics