Logo 
Search:

Unix / Linux / Ubuntu Articles

Submit Article
Home » Articles » Unix / Linux / Ubuntu » Homework HelpRSS Feeds

Script to print all prime numbers from 1 to 300

Posted By: Adelheid Fischer     Category: Unix / Linux / Ubuntu     Views: 20756

Write a script to print all prime numbers from 1 to 300.

Code for Script to print all prime numbers from 1 to 300 in Unix / Linux / Ubuntu

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
  
Share: 


Didn't find what you were looking for? Find more on Script to print all prime numbers from 1 to 300 Or get search suggestion and latest updates.

Adelheid Fischer
Adelheid Fischer author of Script to print all prime numbers from 1 to 300 is from Frankfurt, Germany.
 
View All Articles

 

Other Interesting Articles in Unix / Linux / Ubuntu:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!