Shell script to read a number and find whether the number is odd or even

Posted on in Categories Decision Making last updated April 5, 2008

12 comment

  1. echo “enter the number”
    read n

    2num=$(( $n % 2 ))
    if [ $num -eq 0 ]

    then
    echo “$n number is even”
    else
    echo “$n number is odd”
    fi

  2. echo “Program to check even or odd number”
    echo “Enter a number”
    read n
    a=expr $n % 2
    if [ $a -eq 0 ] ; then #Semicolon is most important for Executing if-else
    echo “It is an even number”
    else
    echo “It is an odd number”
    fi

Leave a Comment