WA Shell script example

WA Shell script to find given number is odd or even.

echo "Enter No"
read a
e=`expr $a % 2`
if test $e -eq 0
then
echo "Even"
else
echo "odd"
fi


2. WA Shell script to find given number is prime or not.

echo "enter no"
read n
i=1
k=0
while [ $i -lt $n  ]
do
      j=`expr $n % $i`
      if [ $j -eq 0  ]
      then
            k=`expr $k + $i` 
      fi
      i=`expr $i + 1`
done

if [ $k -eq $n  ]
then
      echo "No. is prime"
else
      echo "No. is not prime"
fi

3. WA Shell script to find factorial of a given number.

echo "Enter the No"
read a
fact=1
no=$a

while [ $no -ge 1 ]
do
      fact=`expr $fact \* $no`
      let no--
done
echo "factorial of $a is $fact"