Write a shell script to check whether a given number is prime or not

Source Code

f=0
read i
        for (( j=2; j<=$i/2; j++))
                do
                        if [ $((i%j)) == 0 ]
                        then
                                f=1
                                echo -e "$i is not a prime number \n"
                                break
                        fi
                done

if [[ $f == 0 ]]
then
	echo -e $i "is a Prime Number"
fi

Leave a Comment

Your email address will not be published. Required fields are marked *