Tuesday, 11 June 2013

shell script to accept two numbers from user and display n^y using while loop.

Code:
echo Enter value for n:
read n
echo Enter value for y:
read y
iter=1
sum=1
while [ $iter -le $y ]
do
        let sum=sum*n
        let iter=$iter+1
done
echo $sum



Output:
[ty2011330@localhost ~]$ sh file21.sh
Enter value for n:
2
Enter value for y:
3
8

No comments:

Post a Comment