text: Program to find the largest and smallest ASCII valued characters in a string | C ++ program to find largest and smallest characters in a string . ; function that return the largest alphabet . ; initializing max alphabet to ' a ' ; find largest alphabet ; returning largest element ; function that return the smallest alphabet ; initializing smallest alphabet to ' z ' ; find smallest alphabet ; returning smallest alphabet ; Driver Code ; Character array ; Calculating size of the string ; calling functions and print returned value
code: #include <iostream> NEW_LINE using namespace std ; char largest_alphabet ( char a [ ] , int n ) { char max = ' A ' ; for ( int i = 0 ; i < n ; i ++ ) if ( a [ i ] > max ) max = a [ i ] ; return max ; } char smallest_alphabet ( char a [ ] , int n ) { char min = ' z ' ; for ( int i = 0 ; i < n - 1 ; i ++ ) if ( a [ i ] < min ) min = a [ i ] ; return min ; } int main ( ) { char a [ ] = " GeEksforGeeks " ; int size = sizeof ( a ) / sizeof ( a [ 0 ] ) ; cout << " Largest ▁ and ▁ smallest ▁ alphabet ▁ is ▁ : ▁ " ; cout << largest_alphabet ( a , size ) << " ▁ and ▁ " ; cout << smallest_alphabet ( a , size ) << endl ; return 0 ; }