Loading…
OS · Loops & numbers · Program 05 · In the record
write a shell script to input a number and print the reverse of that number
1#!/bin/bash2 3echo "Enter a number:"4read n5 6num=$n7rev=08 9while (( num > 0 ))10do11 digit=$((num % 10))12 rev=$((rev * 10 + digit))13 num=$((num / 10))14done15 16echo "Reverse of $n = $rev"12345Enter a number: 12345 Reverse of 12345 = 54321
Run program 05 in your browser
bash · just-bash. Change the code or the input, run it, break it, and see what happens.