Program:
echo "Enter a number"
read num
sum=0
rev=0
while test $num -gt 0
do
r=`echo $num % 10|bc`
sum=`echo $sum + $r|bc`
rev=`expr \( $rev \* 10 \) + $r`
num=`echo $num /10|bc`
done
echo sum of the digits are $sum
echo reverse of given number $rev
Input/OutPut
Enter a number
12345
sum of the digits are 15
reverse of given number 54321
No comments:
Post a Comment