Largest and smallest digit of a number | C # program to largest and smallest digit of a number ; Function to the largest and smallest digit of a number ; Find the largest digit ; Find the smallest digit ; Driver code ; Function call
using System ; class GFG { static void Digits ( int n ) { int largest = 0 ; int smallest = 9 ; while ( n != 0 ) { int r = n % 10 ; largest = Math . Max ( r , largest ) ; smallest = Math . Min ( r , smallest ) ; n = n / 10 ; } Console . WriteLine ( largest + " ▁ " + smallest ) ; } public static void Main ( String [ ] args ) { int n = 2346 ; Digits ( n ) ; } }