0% found this document useful (0 votes)
79 views30 pages

Sirifort Institute of Management Studies: Guru Gobind Singh Indraprastha University Sector 16 C, Dwarka, Delhi, India

This document appears to be a lab assignment submitted by a student named Nikhil Jayant with enrollment number 42224302018. It contains 26 questions asking the student to write shell scripts to perform various tasks like finding the greatest of two numbers, checking if a number is prime, calculating factorials, printing patterns, checking palindrome strings, calculating simple interest, and more. It provides the guidelines and tasks to be completed in a Linux shell scripting lab course.

Uploaded by

RNT 100
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
79 views30 pages

Sirifort Institute of Management Studies: Guru Gobind Singh Indraprastha University Sector 16 C, Dwarka, Delhi, India

This document appears to be a lab assignment submitted by a student named Nikhil Jayant with enrollment number 42224302018. It contains 26 questions asking the student to write shell scripts to perform various tasks like finding the greatest of two numbers, checking if a number is prime, calculating factorials, printing patterns, checking palindrome strings, calculating simple interest, and more. It provides the guidelines and tasks to be completed in a Linux shell scripting lab course.

Uploaded by

RNT 100
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 30

Guru Gobind Singh Indraprastha University

Sector −16 C, Dwarka, Delhi, India

Practical−X Linux Lab


BCA−352
By
Name: Nikhil Jayant
Enrolment No: 42224302018

Under the guidance:

DR.Anukool Bajpai
Principal

Sirifort Institute of Management Studies


Plot No.8, Institutional Area Rohini Sector−25, New Delhi-110085
CONTENT
PAGE
S.No. Particulars Dated Signature
1. Write a shell script to find the greatest out of
two
numbers.
2. Write a shell script to check if a number is
prime
or not.
3. Write a shell script to check if a number is
Armstrong or not.
4. Write a shell script to find factorial of a number.
5. Write a shell script to print reverse of a
number.
6. Write a shell script to print Fibonacci series
from 1
to 50.
7. Write a shell script to print the following
pattern: 1
12
123
1234
12345
8. Write a shell script to show current time only.
9. Write a shell script to print reverse of a string
and
check if it is palindrome or not.
10. Write a shell script to calculate the Simple
Interest.
11. Write a shell script to find the addition of two
numbers.
12. Write a shell script to find the subtraction of
two
numbers.
13. Write a shell script to find the multiplication of
two numbers.
14. Write a shell script to find the division of two
numbers.
15. Write a shell script to find the modulus of two
numbers.
16. Write a shell script to calculate the area of a
rectangle.
17. Write a shell script to find the circumference of
a
circle.
18. Write a shell script to find the area of a circle.
19. Write a shell script to find the inputted year is a
leap year or not.
20. Write a shell script to find the inputted number
is
odd or even number.
21. Write a shell script to find the percentage of
five marks and also calculate the grades based
on the calculated percentage as follows:
>=75 Grade A
<75 & >=60 Grade B
<60 & >=55 Grade C
<55 & >=50 Passed
<50 Failed

22. Write a shell script to check if the user


entered
userid and password is correct or not.

23. Write a shell script to calculate the electricity


bill.

24. Write a shell script to display Chess Board.

25. Write a shell script to print odd number


series
from 1 to 50.

26. Write a shell script to print even numbers


from a
series of 1 to 50.
Q1.

clear
echo "a shell script to find out the large between two number."
echo -n "First number:"
read fst_num
echo -n "Second number:"
read snd_num
if test $fst_num -gt $snd_num
then
echo $fst_num is greater than $snd_num.
else
echo $snd_num is greater than $fst_num.
fi

Q2.
echo "enter number"

read num

function prime

for((i=2; i<=num/2; i++))

do

if [ $((num%i)) -eq0 ]

then

echo "$num is not a prime number."

exit

fi

done

echo "$num is a prime number."

r=`prime $number`

echo "$r"

Q3.
echo "Enter the number"

read n

function ams

t=$n

s=0

b=0

c=10

while [ $n -gt $b ]

do

r=$((n % c))

i=$((r * r * r))

s=$((s + i))

n=$((n / c))

done

echo $s

if [ $s == $t ]

then

echo "Amstrong number"

else

echo "Not an Armstrong number"

fi

result=`ams $n`

echo "$result"
Q4.
echo "Enter a number"

read n

f=1

while [ $n -gt1 ]

do

f=$((f * n)) #f = f * n

n=$((n - 1)) #n= n - 1

done

echo $f

Q5.
echo enter n

read n

num=0

while [ $n -gt0 ]

do

num=$(expr $num \* 10)

k=$(expr $n % 10)

num=$(expr $num + $k)

n=$(expr $n / 10)

done

echo number is $num


Q6.

echo "Program to Find Fibonacci Series"


echo "How many number of terms to be generated ?"
read n
x=0
y=1
i=2
echo "Fibonacci Series up to $n terms :"
echo "$x"
echo "$y"
while [ $i -lt $n ]
do
i=`expr $i + 1 `
z=`expr $x + $y `
echo "$z"
x=$y
y=$z
done
Q7

.
c=6;
m=1;
for((i=1;i<=5;i++))
do
for((k=1;k<=c;k++))
do
  echo -n  " "
done
for((j=1;j<=i;j++))
do
echo -n "$j"
echo -n " "
done
c=$(($c-1))
echo -e " "
done
exit 0
Q8.

now=$(date +"%T")

echo "Current time : $now"


Q9

clear

echo "Enter a string to be entered:"

read str

echo

len=`echo $str | wc -c`

len=`expr $len - 1`

i=1

j=`expr $len / 2`

while test $i -le $j

do

k=`echo $str | cut -c $i`

l=`echo $str | cut -c $len`

if test $k != $l

then

echo "String is not palindrome"

exit

fi

i=`expr $i + 1`

len=`expr $len - 1`

done

echo "String is palindrome"


Q10

echo " Enter the principle value: "

read p

echo " Enter the rate of interest:"

read r

echo " Enter the time period:"

read t

s=`expr $p \* $t \* $r / 100`

echo " The simple interest is "

echo $s
Q11

#!/bin/bash

# Take input from user and calculate sum.

read -p "Enter first number: " num1

read -p "Enter second number: " num2

sum=$(( $num1 + $num2 ))

echo "Sum is: $sum"


Q12

#!/bin/bash

# Take input from user and calculate substraction.

read -p "Enter first number: " num1

read -p "Enter second number: " num2

sub=$(( $num1 - $num2 ))

echo "Substraction is: $sub"


Q13.

#!/bin/bash

# Program name: "multiply.sh"

# Linux shell script program to multiply two numbers.

echo "Enter num1: "

read num1

echo "Enter num2: "

read num2

multiply=`expr $num1 \* $num2`

echo "Multiplication is: $multiply"


Q14

#!/bin/bash

# Take input from user and calculate division.

read -p "Enter first number: " num1

read -p "Enter second number: " num2

div=$(( $num1 / $num2 ))

echo "division is: $div"


Q15

#!/bin/bash

# Take input from user and calculate modulus.

read -p "Enter first number: " num1

read -p "Enter second number: " num2

mod=$(( $num1 % $num2 ))

echo "modulus is: $mod"


Q16

read -p "Enter a length: " length

read -p "Enter a width: " width

area=$[$length*$width]

echo "The area of the rectangle is $area"


Q19

leap=$(date +"%Y")

echo taking year as $leap

if [ `expr $leap % 400` -eq 0 ]

then

echo leap year

elif [ `expr $leap % 100` -eq 0 ]

then

echo not a leap year

elif [ `expr $leap % 4` -eq 0 ]

then

echo leap year

else

echo not a leap year

fi
Q20

clear

echo "---- EVEN OR ODD IN SHELL SCRIPT -----"

echo -n "Enter a number:"

read n

echo -n "RESULT: "

if [ `expr $n % 2` == 0 ]

then

echo "$n is even"

else

echo "$n is Odd"

fi
Q24

for (( i = 1; i <= 9; i++ )) ### Outer for loop ###

do

for (( j = 1 ; j <= 9; j++ )) ### Inner for loop ###

do

tot=`expr $i + $j`

tmp=`expr $tot % 2`

if [ $tmp -eq 0 ]; then

echo -e -n "\033[47m "

else

echo -e -n "\033[40m "

fi

done

echo -e -n "\033[40m" #### set back background colour to black

echo "" #### print the new line ###


done
Q23

#!/bin/bash

echo -----------------------------------------

echo 'tCalculate Electricity Charge'

echo -----------------------------------------

echo Enter the unit

read unit

if [ $unit -gt 0 ] && [ $unit -le 50 ]

then

charge=$(( $unit * 75 / 100))

echo $charge

elif [ $unit -gt 50 ] && [ $unit -le 150 ]

then

charge=$((( $unit - 50 ) * 130 /100 + 50 * 75 / 100 ))

echo "$charge"

elif [ $unit -gt 150 ] && [ $unit -le 250 ]

then

charge=$((( $unit - 150 ) * 145 /100 + 50 * 75 / 100 + 100 * 130 / 100 ))

echo "$charge"

elif [ $unit -gt 250 ]

then

charge=$((( $unit - 250 ) * 155 /100 + 50 * 75 / 100 + 100 * 130 / 100 ++

100 * 145 / 100 ))

echo "$charge"
fi

t=$(( $charge * 125/100 ))

echo -----------------------------------------

echo 'tElectricity Billing'

echo -----------------------------------------

echo "Unit : $unit"

echo "charge: $t "

echo ----------------------------------------
Q25

echo "enter n value as range to calculate odd."

read n

i=1

while [ $i -le $n ]

do

if [ `expr $i % 2` -eq 0 ]

then

even=$i

else

echo odd=$i

fi

i=`expr $i + 1`

done
Q26

echo "enter n value as range to calculate even number"

read n

i=1

while [ $i -le $n ]

do

if [ `expr $i % 2` -eq 0 ]

then

echo even=$i

else

odd=$i

fi

i=`expr $i + 1`

done

You might also like