C Program to find the smallest digit of a number
In this program, You will learn how to find the smallest digit of a number in c.
1234 => Smallest digit is: 1
Example: How to find the smallest digit of a number in c.
#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("Smallest digit:%d", sm);
return 0;
}
Output:
Enter a number:34214
Smallest digit:1