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.


1234 => Smallest digit is: 1


Example: How to find smallest digit of a number in c

Run it Now
#include<stdio.h>

int main() {

   int n, r, sm = 9;

   printf("Enter a Number :");
   scanf("%d", &n);

   while (n > 0) {
       r = n % 10;
       if (sm > r) {
           sm = r;
       }
       n = n / 10;
   }
   printf("\nThe Smallest Digit :%d", sm);

   return 0;
}

Output:

Enter a Number :4326
The Smallest Digit :2