answersLogoWhite

0


Best Answer

# Algo:

# 1) Input number n

# 2) Set rev=0, sd=0

# 3) Find single digit in sd as n % 10 it will give (left most digit)

# 4) Construct revrse no as rev * 10 + sd

# 5) Decrment n by 1

# 6) Is n is greater than zero, if yes goto step 3, otherwise next step

# 7) Print rev

#

if [ $# -ne 1 ]

then

echo "Usage: $0 number"

echo " I will find reverse of given number"

echo " For eg. $0 123, I will print 321"

exit 1

fi

n=$1

rev=0

sd=0

while [ $n -gt 0 ]

do

sd=`expr $n % 10`

rev=`expr $rev \* 10 + $sd`

n=`expr $n / 10`

done

echo "Reverse number is $rev"

User Avatar

Wiki User

15y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a shell script to print given number in reverse order in Unix?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

How do you write a program that outputs a given characters in reverse?

write the javascript code to display the reverse no. of given no. (e.g. 247 reverse of 742)


How do you convert a number that consist of alphabet and number in reverse order?

To reverse a number, first convert the number to a string, then reverse the string. Given your number consists of alphanumeric characters, the number must already be a string so simply reverse the string: #include<string> using std::string; string reverse (const string& s) { string str {}; for (auto c : s) str.insert (str.begin(), c); return str; } int main () { std::cout << "Enter a number: "; string s {}; std::cin >> s; std::cout << "The number in reverse is: " << reverse (s); }


How do find factorial using vbscript?

<html> <script language="vbscript"> n=cint(inputbox("Enter a number")) dim f f=1 if n<0 then Msgbox "Invalid number" elseif n=0 or n=1 then MsgBox "The factorial of given number "&n&" is :"&f else for i=n to 2 step -1 f=f*i next MsgBox "The factorial of given number "&n&" is :"&f end if </script> </html>


What is a script on scratch?

Script is step wise instructions given to a sprite. For example- When green flag clicked Pen down Move 100 steps In simple language, commands given to a sprite.


Write a program to find the reverse of a given number with help of function?

//Reverse of the Number #include<stdio.h> #include<conio.h> int main () { int num,mod,rev=0; printf("Enter a number:"); scanf("%d", &num); while (num>0) { mod=num%10; rev=(rev*10)+mod; num=num/10; } printf("Reverse of the given number: %d", rev); getchar(); return 0; } // alternative solution based on reversing the alphanumeric representation of // the number: void rev(int me) { char alpha[32]; sprintf(alpha, "%d", me); for (const char* cp = alpha + strlen(alpha) - 1; cp >= alpha; --cp) { putchar(cp); } }

Related questions

How can you generate a palindrome from a given number?

You write the number and then follow it with the digits in reverse order.


How do you write a program that outputs a given characters in reverse?

write the javascript code to display the reverse no. of given no. (e.g. 247 reverse of 742)


Write a shell script to count the number of times is appears in a given text file?

You don't need a shell script to do this; use the 'grep' command with the '-c' option to count the number of occurrences of some pattern.


How do you write a shell script which counts the number of lines and words present in a given file?

#!/bin/sh wc -lw "$1"


Fox pro program to reverse the given number?

reverse programe in fox pro


How do you write a shell script which counts the last 10 lines present in a given file?

You don't need a shell script to do this - just use the 'tail' command.


Enter a number and draw a flow chart to get the reverse of the given number and the number is 435?

123


To write shell program to check the given number and its reverse are same?

echo "enter the number" if [ $# -ne 1 ] then echo "Usage: $0 number" echo " I will find reverse of given number" echo " For eg. $0 12321, I will print 12321" exit 1 fi n=$1 rev=0 sd=0 while [ $n -gt 0 ] do sd=`expr $n % 10` rev=`expr $rev \* 10 + $sd` n=`expr $n / 10` done echo "Reverse number is $rev"


Write a shell script to check whether the given input is prime or not?

shell script for check whether the given no is prime or not??echo "input any number:"read nono=`expr $no`i=`expr 2`while [ $i -lt $no ]doif [ `expr $no % $i` -eq 0];thenecho "$no is not a prime no.."break 2fii=`expr $i +1`doneif [ $i -eq $no ];thenecho "$no is a PRIME no..."fi


What can the reverse lookup be used to find?

The reverse lookup is a telephone number data base. Instead of looking up a phone number based on a given name, a name can be looked up based on a given phone number. It is useful when receiving phone calls from an unknown phone number.


How do i write an emcee script for a welcome ceremony?

just have a clear sequence of who are the guest speakers.. and breiefly introduce them after yoy have given info about the ceremomy.


What name is given to prime numbers that you can reverse to make another prime number?

A mirror prime.