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 ; Input String ; Calculating size of the string ; calling functions and print returned value
code: using System ; class GFG { static char largest_alphabet ( String a , int n ) { char max = ' A ' ; for ( int i = 0 ; i < n ; i ++ ) if ( a [ i ] > max ) max = a [ i ] ; return max ; } static char smallest_alphabet ( String a , int n ) { char min = ' z ' ; for ( int i = 0 ; i < n - 1 ; i ++ ) if ( a [ i ] < min ) min = a [ i ] ; return min ; } public static void Main ( ) { String a = " GeEksforGeeks " ; int size = a . Length ; Console . Write ( " Largest ▁ and ▁ smallest ▁ alphabet ▁ is ▁ : ▁ " ) ; Console . Write ( largest_alphabet ( a , size ) + " ▁ and ▁ " ) ; Console . Write ( smallest_alphabet ( a , size ) ) ; } }