Shell Script to print given number in reverse order - The Coding Shala

Home >> Scripting >> reverse order of a number

Shell Script to print given number in reverse order

Write a shell script to print given the number in reverse order?



Code: 

#!/bin/bash
n=$1
rev=0
tmp=0

while [ $n -gt 0 ]
do
tmp=`expr $n % 10`
rev=`expr $rev \* 10 + $tmp`
n=`expr $n / 10`
done
echo "reverse no is $rev"



Other Posts You May Like
Please leave a comment below if you like this post or found some error, it will help me to improve my content.

Comments

Popular Posts from this Blog

Longest Substring Without Repeating Characters Java Program - The Coding Shala

Java Program to Reverse a String using Stack - The Coding Shala

Anti Diagonals - The Coding Shala

Time Complexity, Space Complexity, Asymptotic Notations - The Coding Shala

Java Program to Find GCD or HCF of Two Numbers - The Coding Shala