Thursday, May 1, 2008

Write a shell script to print natural numbers up to ‘n’ using while loop.

echo “Upper limit”
read n
$i = 1
while [$i -lt $n]
do
echo $i
expr ‘$i=$i+1’

done

1 comment:

Anonymous said...

your code has errors
this is the correct one

echo "enter value of n"
read n
echo "natural numbers:"
i=1
while [ $i -le $n ]
do
echo $i
i=`expr $i + 1`
done