C++ Program to find smallest digit of a number


In this program, You will learn how to find smallest digit of a number in C++.


Number is : 1234

Smallest digit is : 1


Example: How to find smallest digit of a number in C++

Run it Now
#include<iostream>
using namespace std;

int main() {

  int a, r, smallest = 9;

  cout << "Enter a number :";
  cin>>a;

  while (a > 0) {
      r = a % 10;
      if (smallest > r) {
          smallest = r;
      }
      a = a / 10;
  }
  cout << "\nSmallest Digit is :" << smallest;

  return 0;
}
 

Output:

Enter a number :438
Smallest Digit is :3