Tuesday, January 24, 2023

Unix Shell Programming Example for B.Sc, B.Tech, BCA, MCA

 9. Check if a number is prime fibonacci.

PROGRAM:

echo "enter the ending range of the series:"
read n
a=0
b=1
d=0
echo "The series is:"
if [ $n -le 2 ]
then
    echo "null"
else
    while [ $d -le $n ]
    do
        d=`expr $a + $b`
        c=0
        e=1
        while [ $e -le $d ]
        do
            if [ `expr $d \% $e` -eq 0 ]
            then
                c=`expr $c + 1`
            fi
            e=`expr $e + 1`
        done
        if [ $c -eq 2 ]
        then
            if [ $d -le $n ]
            then
                echo $d
            fi
        fi
        a=$b
        b=$d
    done
fi


OUTPUT:

[bgc@localhost ~]$ sh 10.sh
enter the ending range of the series:
100
The series is:
2
3
5
13
89
[bgc@localhost ~]$

No comments:

Post a Comment