1
Largest & Smallest Digit of a Number
Problem Solving
Problem: Find the largest and the smallest digit of a number.
int num = 234515;
int lrg = 0;
do{
int digit = num % 10;
if(digit > lrg) lrg = digit;
num = num / 10;
}while(num != 0);
cout << lrg; // 5
int num = 234515;
int small = 9;
do{
int digit = num % 10;
if(digit < small) small = digit;
num = num / 10;
}while(num != 0);
cout << small; // 1