Write a Linux shell script to generate prime number from 1 to n, where n is any positive integer number entered by user, Unix program for prime numbers from 1 to n
Program
clear
echo "Enter the number upto which you want prime numbers:"
read n
for ((i=1;i<=n;++))
do
flag=0
for ((j=2;j<i;j++))
do
if [ 'expr $i % $j' -eq 0]
then
flag=1
fi
done
if [$flag-eq 0]
then
echo $i
fi
done
Output:
Enter the number upto which you want prime numbers:
10
1
2
3
5
7
<<< Previous || Current || Next >>>
i am not getting output for this program please check it is urgent
ReplyDeleteha bata........
DeleteSame here
DeleteI think After the if statement there is space
ReplyDeleteThanks sir it's perfectly working
ReplyDeleteBut there is no need to fi
ReplyDeleteSyntax Error
ReplyDeleteread -p "Enter the number : " n
ReplyDeletefor ((i=1;i<=n;i++))
do
c=0
for ((j=2;j<i;j++))
do
if [[ $((i % j)) -eq 0 ]]
then
c=1
fi
done
if [[ $c -eq 0 ]]
then
echo $i
fi
done
~
its working
ReplyDeleteread -p "Enter the number : " n
for ((i=1;i<=n;i++))
do
c=0
for ((j=2;j<i;j++))
do
if [[ $((i % j)) -eq 0 ]]
then
c=1
fi
done
if [[ $c -eq 0 ]]
then
echo $i
fi
done
~