Tuesday, 11 June 2013

Shell Script to accept a number n from user and display the squares of all numbers from 1 to n

Code:
echo -n "Enter the number : "
read n
c=1
a=1
while test $c -le $n
do
        let a=$c*$c
        echo "$c square = $a"
        let c=c+1
done


Output:
[ty2011330@localhost ~]$ sh j09.sh
Enter the number : 5
1 square = 1
2 square = 4
3 square = 9
4 square = 16
5 square = 25

1 comment:

  1. Strange "water hack" burns 2lbs overnight

    At least 160 thousand men and women are using a simple and secret "liquids hack" to lose 2 lbs each night in their sleep.

    It is easy and it works all the time.

    You can do it yourself by following these easy steps:

    1) Go get a drinking glass and fill it up with water half glass

    2) Then use this amazing HACK

    and be 2 lbs thinner in the morning!

    ReplyDelete