Tuesday, January 24, 2023

Data mining Question set

Question set 1- CLICK
Question set 2-CLICK
Question set 3- CLICK
Question set 4- CLICK
Question set 5- CLICK
Question set 6- CLICK


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

 10. Check strong number.

PROGRAM:

echo "Enter the number:"
read n
fact=1
if [ $n -eq 0 ]
then
    echo "fact = "1
else
   
        for i in `seq 1 $n`
        do
            fact=`expr $fact \* $i`
        done
        echo "fact = $fact"

fi


OUTPUT:

[bgc@localhost ~]$ sh 11.sh
Enter a number:
145
145 is a strong number
[bgc@localhost ~]$ sh 11.sh
Enter a number:
2
2 is a strong number
[bgc@localhost ~]$ sh 11.sh
Enter a number:
23
23 is not a strong number
[bgc@localhost ~]$

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 ~]$

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

 8.Print twin prime numbers within a range.

PROGRAM:

echo "enter a range:"
read a
read b
n=$a
while [ $n -le $b ]
do
    c=0
    d=1
    while [ $d -le $n ]
    do
        if [ `expr $n \% $d` -eq 0 ]
        then
            c=`expr $c + 1`
        fi
        d=`expr $d + 1`
    done

    if [ $c -eq 2 ]
    then
        f=$n
        e=`expr $n + 2`
        m=$e
        c=0
        d=1
        while [ $d -le $m ]
        do
            if [ `expr $m \% $d` -eq 0 ]
            then
                c=`expr $c + 1`
            fi
            d=`expr $d + 1`
        done
        if [ $c -eq 2 ]
        then
            echo "twin prime pair=$f,$e"
        fi
       
    fi
n=`expr $n + 1`
done

OUTPUT:

enter a range:
2
10
twin prime pair=3,5
twin prime pair=5,7
[bgc@localhost ~]$ sh 9.sh
enter a range:
3
100
twin prime pair=3,5
twin prime pair=5,7
twin prime pair=11,13
twin prime pair=17,19
twin prime pair=29,31
twin prime pair=41,43
twin prime pair=59,61
twin prime pair=71,73
[bgc@localhost ~]$

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

 7. Prime number checking.

PROGRAM:

echo "enter a number:"
read n

    c=0
    d=1
    while [ $d -le $n ]
    do
        if [ `expr $n \% $d` -eq 0 ]
        then
            c=`expr $c + 1`
        fi
        d=`expr $d + 1`
    done

if [ $c -eq 2 ]
then
    echo "prime number"
else
    echo "not a prime number"   
fi


OUTPUT:

[bgc@localhost ~]$ sh 8.sh
enter a number:
2
prime number
[bgc@localhost ~]$ sh 8.sh
enter a number:
1
not a prime number
[bgc@localhost ~]$ sh 8.sh
enter a number:
0
not a prime number
[bgc@localhost ~]$ sh 8.sh
enter a number:
5
prime number
[bgc@localhost ~]$ sh 8.sh
enter a number:
4
not a prime number
[bgc@localhost ~]$

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

 6. Print fibonacci series.

PROGRAM:

echo "enter number of elements of the fibonacci series:"
read n
a=0
b=1
if [ $n -eq 0 ]
then
    echo "no elemnts"
else
    if [ $n -eq 1 ]
    then
        echo 0
    else
        echo 0
        echo 1
        c=2
        while [ $c -ne $n ]
        do
            d=`expr $a + $b`
            echo $d   
            a=$b
            b=$d
            c=`expr $c + 1`
        done
    fi
fi

OUTPUT:

[bgc@localhost ~]$ sh 7.sh
enter number of elements of the fibonacci series:
6
0
1
1
2
3
5
[bgc@localhost ~]$

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

 5. Find out the factorial of a number.

PROGRAM:

echo "Enter the number:"
read n
fact=1
if [ $n -eq 0 ]
then
    echo "fact = "1
else
   
        for i in `seq 1 $n`
        do
            fact=`expr $fact \* $i`
        done
        echo "fact = $fact"

fi

OUTPUT:

[bgc@localhost ~]$ sh 6.sh
Enter the number:
3
fact = 6
[bgc@localhost ~]$ sh 6.sh
Enter the number:
2
fact = 2
[bgc@localhost ~]$ sh 6.sh
Enter the number:
0
fact = 1
[bgc@localhost ~]$

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

 4.Check a number whether it is odd positive,odd negative,even positive,even negative.

PROGRAM:

echo "enter a number:"
read n
if [ $n -ge 0 ]
then
    if [ `expr $n % 2` -eq 0 ]
    then
        echo "$n is a even positive number"
    else
        echo "$n is a odd positive number"
    fi
else
    if [ `expr $n % 2` -eq 0 ]
    then
        echo "$n is a even negative number"
    else
        echo "$n is a odd negative number"
    fi
fi


OUTPUT:


[bgc@localhost ~]$ sh 5.sh
enter a number:
3
3 is a odd positive number
[bgc@localhost ~]$ sh 5.sh
enter a number:
0
0 is a even positive number
[bgc@localhost ~]$ -9
bash: -9: command not found...
[bgc@localhost ~]$ sh 5.sh
enter a number:
-9
-9 is a odd negative number
[bgc@localhost ~]$ sh 5.sh
enter a number:
-10
-10 is a even negative number
[bgc@localhost ~]$

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

 3. Leap year checking.

PROGRAM:

echo "enter the year:"
read n
if [ `expr $n % 4` -eq 0 ]
then
    if [ `expr $n % 100` -eq 0 ]
    then
        if [ `expr $n % 400` -eq 0 ]
        then
            echo "$n is a leapyear"   #2000
        else
            echo "$n is not a leapyear"  #1900
        fi
    else
        echo "$n is a leapyear"  #1996
    fi
else
    echo "$n is not a leapyear"  #1997
fi

OUTPUT:

[bgc@localhost ~]$ sh pc2.sh
enter the year:
1996
1996 is a leapyear
[bgc@localhost ~]$ sh pc2.sh
enter the year:
2000
2000 is a leapyear
[bgc@localhost ~]$ sh pc2.sh
enter the year:
1997
1997 is not a leapyear
[bgc@localhost ~]$ sh pc2.sh
enter the year:
1900
1900 is not a leapyear
[bgc@localhost ~]$

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

 2. Use of for loop.

PROGRAM:

echo "Enter number of elements:"
read n
for i in `seq 1 $n`
do
    echo $i
done

OUTPUT:

[bgc@localhost ~]$ sh pc.sh
Enter number of elements:
3
1
2
3
[bgc@localhost ~]$