Count of alphabets having ASCII value less than and greater than k | C ++ implementation of the above approach ; Function to count the number of characters whose ascii value is less than k ; Initialising the count to 0 ; Incrementing the count if the value is less ; return the count ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int CountCharacters ( string str , int k ) { int cnt = 0 ; int len = str . length ( ) ; for ( int i = 0 ; i < len ; i ++ ) { if ( str [ i ] < k ) cnt ++ ; } return cnt ; } int main ( ) { string str = " GeeksForGeeks " ; int k = 90 ; int count = CountCharacters ( str , k ) ; cout << " Characters ▁ with ▁ ASCII ▁ values " " ▁ less ▁ than ▁ K ▁ are ▁ " << count ; cout << " Characters with ASCII values " STRNEWLINE TABSYMBOL TABSYMBOL TABSYMBOL " greater than or equal to K are " << str . length ( ) - count ; return 0 ; }