PC & IT SUPPORT MADE EASY FORUM
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Finding Primes With Bash On Linux TUT

Go down

Finding Primes With Bash On Linux TUT Empty Finding Primes With Bash On Linux TUT

Post by jamied_uk 20th October 2019, 00:15





Code:
#! /bin/bash
low=1
count=0

while [ $low -eq 1 ]
do
echo "Enter the lower limit greater than 1"
read low
done

echo "Enter the upper limit"
read upper


for mun in `seq $low $upper`
do
ret=$(factor $mun | grep $mun | cut -d ":" -f 2 | cut -d " " -f 2)

if [ "$ret" -eq "$mun" ]
then
echo "$mun is a prime number"
((count++))
fi
done

echo -e "\n There are $count number of prime numbers"
jamied_uk
jamied_uk
Admin

Posts : 2952
Join date : 2010-05-09
Age : 41
Location : UK

https://jnet.sytes.net

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum