R 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 R.


5234 = 2

2351 = 1

Example: How to find the smallest digit of a number in R

{
    n = as.integer(readline(prompt = "Enter a number :"))
    sm = 9

    while (n > 0) {
      r = n %% 10
      if (sm > r) {
        sm = r
      }

      n = n %/% 10
    }
    print(paste("Smallest digit is :", sm))
}

Output:

Enter a number :34512
[1] "Smallest digit is : 1"