Search Here

Shell Script to find all prime numbers between two positive integers a and b. a and b are supplied as command line arguments


if (( $#!=2 ))
then
    echo Wrong number of arguments.
else
    a=$1
    b=$2
    if (( a>b ))
    then
        x=$a
        a=$b
        b=$x
    fi
    echo Prime numbers between $a and $b are :
   
    (( i=a ))
    while (( i<=b ))
    do
        set `factor $i`
        if (( $#==2 ))
        then
            echo $i
        fi
        (( i=i+1 ))
    done
fi

No comments:

Post a Comment