You are not logged in or registered. Please login or register to use the full functionality of this Website SybaseTeam.Com...
Hello There, Guest! (LoginRegister) Remember Me? Current time: 10-31-2014, 10:40 PM
   Home  |  About Us  |  Sybase Training  |  Synergy  |  Consulting  |  Job Openings  |  Tech Videos  |  Rules and Disclaimer  |  Search
Post Reply 
Forum Tools
Script to print reverse of a given number using Korn shell functions
06-24-2010, 10:17 AM
Post: #1
Quote this message in a reply
Script to print reverse of a given number using Korn shell functions


#!/usr/bin/ksh

########### Function to reverse a number ##################################

reverse()
{
rev=0
sd=0
n=$1

while [ $n -gt 0 ]
do
sd=`expr $n % 10` # get the remainder of n divided by 10
rev=`expr $rev \* 10`
n=`expr $n / 10`
done

print $rev
}

################### MAIN PROGRAM ###################################

set -vx

echo "This script will print the reverse of a given number."
echo "Enter number:"
read n
echo "Reverse of $n is:" `reverse $n`

exit 0



Think Deeply. Code Well.

Saritha R
Hyderabad.
TechSupport-SeniorMember
Synergy Project (SybaseTeam.Com)
Find all posts by this user
Post Reply 


Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Unix Script to list n month old files Joshi 1 5,210 09-30-2012 04:59 AM
Last Post: hirakrintu
  Executing commands in shell without pressing enter key from keyboard unixlover 2 4,659 02-09-2012 08:23 PM
Last Post: jdcarroll15
  execute shell script in owner privileges arukaru500 0 2,063 12-13-2011 11:28 AM
Last Post: arukaru500
  How to return a value from one shell script to another Suneel 5 4,473 11-30-2011 09:33 PM
Last Post: DerekAsirvadem
  script to generate pseudo random numbers srama2 0 3,325 03-17-2010 09:36 AM
Last Post: srama2
  Shell Programming Control Structures - SH,BASH,KSH,CSH,TCSH quick reference Joshi 0 17,236 03-05-2010 11:01 AM
Last Post: Joshi
  nawk script to print fibonnaci numbers upto 'n' srama2 0 2,167 02-17-2010 02:55 AM
Last Post: srama2
  nawk script to output the factorial of a given number srama2 0 3,043 02-16-2010 07:00 AM
Last Post: srama2
  script to check for palindrome srama2 0 2,833 02-10-2010 04:38 AM
Last Post: srama2
  Debug Unix Shell Scripts john 0 6,529 12-17-2009 09:04 AM
Last Post: john

Options:
Forum Jump:


Contact Us | SybaseTeam | Disclaimer & Rules | Return to Top | Return to Content | Lite (Archive) Mode | RSS Syndication