Showing posts with label shell progrmming. Show all posts
Showing posts with label shell progrmming. Show all posts
Friday, 3 April 2015
Thursday, 2 April 2015
write a shell script to check the given number is armstrong or not
write a shell script to check the given number is armstrong or not
clear
echo enter any number to check armstrong or not
read n
m=$n
sum=0
while [ $m != 0 ]
do
y=`expr $m % 10`
x=`expr $y \* $y \* $y`
sum=`expr $sum + $x`
m=`expr $m / 10`
done
if [ $sum -eq $n ]
then
echo the given number is armstrong
else
echo the given number is not armstrong
fi
output
clear
echo enter any number to check armstrong or not
read n
m=$n
sum=0
while [ $m != 0 ]
do
y=`expr $m % 10`
x=`expr $y \* $y \* $y`
sum=`expr $sum + $x`
m=`expr $m / 10`
done
if [ $sum -eq $n ]
then
echo the given number is armstrong
else
echo the given number is not armstrong
fi
output
Friday, 27 March 2015
Write a shell program to check whether a given string is palindrome or not
2) Write a shell program to check whether a given number is palindrome or not?
clear
echo "Enter the number you want?"
read num
m=$num
rev=0
while [ $num -gt 0 ]
do
r=`expr $num % 10`
rev=`expr $rev \* 10 + $r`
num=`expr $num / 10`
done
if [ $m = $rev ]
then
echo " $m is Palindrome"
else
echo " $m is not Palindrome"
fi
Subscribe to:
Posts (Atom)






