• Home
  • Recent Q&A
  • Java
  • Cloud
  • JavaScript
  • Python
  • SQL
  • PHP
  • HTML
  • C++
  • Data Science
  • DBMS
  • Devops
  • Hadoop
  • Machine Learning
in DevOps by
Q:
Write a shell script to print only prime numbers?

2 Answers

0 votes
by

prime.sh

echo "1"

i=3

j=300

flag=0

tem=2

echo "1"while [ $i -ne $j ]

do

        temp=`echo $i`

        while [ $temp -ne $tem ]

        do

                temp=`expr $temp - 1`

                n=`expr $i % $temp`

                if [ $n -eq 0 -a $flag -eq 0 ]

                then

                        flag=1

                fi

        done

        if [ $flag -eq 0 ]

        then

                echo $i

        else

                flag=0

        fi

        i=`expr $i + 1`

done

0 votes
by

Below is the program to find only prime numbers

prime.sh

echo "1"

i=3

j=300

flag=0

tem=2

echo "1"while [ $i -ne $j ]

do

        temp=`echo $i`

        while [ $temp -ne $tem ]

        do

                temp=`expr $temp - 1`

                n=`expr $i % $temp`

                if [ $n -eq 0 -a $flag -eq 0 ]

                then

                        flag=1

                fi

        done

        if [ $flag -eq 0 ]

        then

                echo $i

        else

                flag=0

        fi

        i=`expr $i + 1`

done

Related questions

+1 vote
asked Jul 9 in NumPy by rajeshsharma
0 votes
asked Oct 24, 2020 in JAVA by sharadyadav1986
...