R Program to reverse a number


In this program, You will learn how to reverse a number in R.


123 => 321

102 => 201

Example: How to reverse a number in R

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

    while (n > 0) {
      r = n %% 10
      rev = rev * 10 + r
      n = n %/% 10
    }

    print(paste("Reverse number is :", rev))
}

Output:

Enter a number :102
[1] "Reverse number is : 201"