Largest and smallest digit of a number | CPP 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; void Digits ( int n ) { int largest = 0 ; int smallest = 9 ; while ( n ) { int r = n % 10 ; largest = max ( r , largest ) ; smallest = min ( r , smallest ) ; n = n / 10 ; } cout << largest << " ▁ " << smallest ; } int main ( ) { int n = 2346 ; Digits ( n ) ; return 0 ; }