Monday 9 July 2012

Write a shell script that takes two number s through keyboard and finds the value od one number raised to the power of another.




echo "Enter a number: "
read a

echo "Enter Power: "
read p

i=1
ans=1
while [ $i -le $p ]
do
ans=`expr $ans \* $a`
i=`expr $i + 1`
done
echo "Answer of $a^$p is $ans"

--------------------------------------------------------------------------------------------------------------
                OUTPUT
Enter a number: 10
Enter Power: 3
Answer of 10^3 is 1000

0 comments:

Post a Comment