Back In the print window choose "Save as PDF" as the destination
NOTE.CS

Largest & Smallest Digit of a Number

1 topic · 28 Nov 2026
1

Largest & Smallest Digit of a Number

Problem Solving
Problem: Find the largest and the smallest digit of a number.
Largest digit · C++
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
Smallest digit · C++
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