Write a shell
script to print all even and odd number from 1 to 10.
Script:
echo enter n value as
range to calculate odd and even numbers.
read n
i=1
while [ $i -le $n ]
do
if [ `expr $i % 2` -eq 0 ]
then
echo even=$i
else
echo odd=$i
fi
i=`expr $i + 1`
done
Output:
[root@localhost shell_script]# bash
oddeven.sh
enter n value as range to calculate odd
and even numbers.
10
odd=1
even=2
odd=3
even=4
odd=5
even=6
odd=7
even=8
odd=9
even=10
No comments:
Post a Comment