Given a string, the task is to find the average of ASCII values of characters in the string.
Input: str = "for" Output: 109 'f'= 102, 'o' = 111, 'r' = 114 (102 + 111 + 114)/3 = 109 Input: str = "geeks" Output: 105
Source : Microsoft Internship Experience
Approach : Start iterating through characters of the string and add their ASCII value to a variable. Finally, divide this sum of ASCII values of characters with the length of string i.e, total number of characters in the string.
Time Complexity: O(l), where l is the length of the string.
Auxiliary Space: O(1)
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.
- Print each word in a sentence with their corresponding average of ASCII values
- Subsequences generated by including characters or ASCII value of characters of given string
- Program to find the product of ASCII values of characters in a string
- Count characters in a string whose ASCII values are prime
- Program to find the XOR of ASCII values of characters in a string
- Find the sum of the ascii values of characters which are present at prime positions
- Split a given string into substrings of length K with equal sum of ASCII values
- Check if a string contains only alphabets in Java using ASCII values
- Convert a string to hexadecimal ASCII values
- Program to find the largest and smallest ASCII valued characters in a string
- Count pairs of characters in a string whose ASCII value difference is K
- Minimum, maximum and average price values for all the items of given type
- Map function and Dictionary in Python to sum ASCII values
- Minimize ASCII values sum after removing all occurrences of one character
- Count the number of words having sum of ASCII values less than and greater than k
- Sums of ASCII values of each word in a sentence
- Sub-strings having exactly k characters that have ASCII value greater than p
- Convert all lowercase characters to uppercase whose ASCII value is co-prime with k
- Find number of substrings of length k whose sum of ASCII value of characters is divisible by k
- Decode an Encoded Base 64 String to ASCII String
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.