R Program to find the largest digit of a number


In this program, You will learn how to find the largest digit of a number in R.


1234 = 4

2351 = 5

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

{
    n = as.integer(readline(prompt = "Enter a number :"))
    largest = 0

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

      n = n %/% 10
    }
    print(paste("Largest digit is :", largest))
}

Output:

Enter a number :12432
[1] "Largest digit is : 4"