language: Bash (bash 4.0.35)
date: 110 days 9 hours ago
link:
visibility: public
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
if [ $# -eq 0 ]     #  Arguments Checking   
then 
        echo -n "Enter the number: " 
        read n 
else 
        n=$1 
fi 
 
[ $1 -lt 2 ] && echo "Values < 2 are not prime numbers" && exit 1
 
i=3 
echo -n "Prime Factors of $1: "
 
while [ $i -le $n ] 
do 
        rem=`expr $n % $i` 
        if [ $rem -eq 0 ] 
        then 
                j=2 
                while [ $j -lt $i ] 
                do 
                        temp3=`expr $i % $j` 
                        if [ $temp3 -eq 0 ] 
                        then 
 
                                break 
                        fi 
                        j=`expr $j + 1` 
                done 
                if [ $j -eq $i ] 
                then 
                        echo -n '$i' 
                fi 
        fi 
 
        i=`expr $i + 1` 
done