Sunteți pe pagina 1din 9

NAME:-SACHIN HARIBA METKARI

CLASS:-SYIT/B
ROLL NO:-2532
ASSIGNMENT NO 6

Q.1 Write a shell program to add two integers?


Ans: [sachin2532@Lab1 sachin2532]$ vi sachin32.sh
echo "enter the first number"
read num1
echo "enter the second number"
read num2
num3=`expr $num1 + $num2`
echo $num3
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
-- INSERT -- 1,1 All
"sachin32.sh" 7L, 119C 1,1 All
E138: Can't write viminfo file /home/sachin2532/.viminfo!
Hit ENTER or type command to continue
[sachin2532@Lab1 sachin2532]$ sh sachin32.sh
enter the first number
6
enter the second number
7
13

1
NAME:-SACHIN HARIBA METKARI
CLASS:-SYIT/B
ROLL NO:-2532

Q.2 Write a shell program for all arithmetic operation?


Ans: [sachin2532@Lab1 sachin2532]$ vi s-32.sh
echo "enter the first number"
read num1
echo "enter the second number"
read num2
sum=`expr $num1 + $num2`
sub=`expr $num1 - $num2`
mul=`expr $num1 \* $num2`
div=`expr $num1 / $num2`
echo $sum
echo $sub
echo $mul
echo $div
~
~
~
~
~
~
~
~
~
~
-- INSERT -- 1,1 All
"s-32.sh" [New] 13L, 223C written
E138: Can't write viminfo file /home/sachin2532/.viminfo!
Hit ENTER or type command to continueZ
[sachin2532@Lab1 sachin2532]$ sh s-32.sh
enter the first number
6
enter the second number
3
9
3
18
2

2
NAME:-SACHIN HARIBA METKARI
CLASS:-SYIT/B
ROLL NO:-2532

Q.3 Write a shell program to check whether the number is


even or odd?
Ans: [sachin2532@Lab1 sachin2532]$ vi sachin-32.sh
echo "enter the number"
read num1
num3=`expr $num1 % 2`
if [ $num3 -eq 0 ]
then
echo "even"
else
echo "odd"
fi
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
E138: Can't write viminfo file /home/sachin2532/.viminfo!
Hit ENTER or type command to continue
[sachin2532@Lab1 sachin2532]$ sh sachin-32.sh
enter the number
10
even
[sachin2532@Lab1 sachin2532]$ sh sachin-32.sh
enter the number
7
Odd

3
NAME:-SACHIN HARIBA METKARI
CLASS:-SYIT/B
ROLL NO:-2532
Q.4 Write a program to find area of circle, triangle, rectangle
and squares?
Ans:[student@Lab1 sachin2532]$ vi area2532.sh
echo "enter the number"
read r
read p
circ=`expr $p \* $r \* $r`
echo $circ
echo "enter the base"
read b
echo "enter the height"
read h
read d
triangle=`expr $d \* $b \* $h`
rectangle=`expr $b \* $h`
echo $triangle
echo $rectangle
echo "enter the sides"
read s
squares=`expr $s \* $s`
echo $squares
~
~
~
~
~
~
~
~
~
~
~
-- INSERT -- 14,16 All
[student@Lab1 sachin2532]$ sh area2532.sh
enter the number
2
3
12

4
NAME:-SACHIN HARIBA METKARI
CLASS:-SYIT/B
ROLL NO:-2532
enter the base
4
enter the height
2
1
8
8
enter the sides
4
16

Q.5 Write a program to find percent of a student as per marks


given for 12 subjects?
Ans:[student@Lab1 sachin2532]$ vi percentage.sh
echo `enter marks obtained in 12 subjects`
read s1 s2 s3 s4 s5 s6 s7 s8 s9 s10 s11 s12
sum=`expr $s1 + $s2 + $s3 + $s4 + $s5 + $s6 + $s7 + $s8 + $s9 + $s10 + $s11 + $s
12`
per=`expr $sum / 12`
echo "percentage=" $per
~
~
~
~
~
~
-

- INSERT -- 5,24 All


E138: Can't write viminfo file /home/student/.viminfo!
Hit ENTER or type command to continue

[student@Lab1 sachin2532]$ sh percentage.sh


enter marks obtained in 12 subjects
60 60 60 60 60 60 60 60 60 60 60 60
percentage= 60

5
NAME:-SACHIN HARIBA METKARI
CLASS:-SYIT/B
ROLL NO:-2532
Q.6 Write down the shell program enter the character from the user
and find out whether it is a digit, capital letter or small letter or a
symbol?
Ans:[student@Lab1 sachin2532]$ vi character.sh
echo "enter any character"
read ch
case $ch in
[0-9]) echo "it is a digit"
;;
[A-Z]) echo "it is a capital letter"
;;
[a-z]) echo "it is small letter"
;;
[*]) echo "it is a symbol"
;;
esac
~
~
~
~

~
~
~
~
~
~
-- INSERT -- 0,1 All
E138: Can't write viminfo file /home/student/.viminfo!

Hit ENTER or type command to continue


[student@Lab1 sachin2532]$ sh character.sh
enter any character
A
it is a capital letter

[student@Lab1 sachin2532]$ sh character.sh


enter any character
*
it is a symbol
[student@Lab1 sachin2532]$ sh character.sh
enter any character
a
it is small letter

6
NAME:-SACHIN HARIBA METKARI
CLASS:-SYIT/B
ROLL NO:-2532

Q.7 Write a shell script to check whether word begins with small case
vowel or capital case vowel or ends with any digit?
Ans: [student@Lab1 sachin2532]$ vi vowel.sh
echo "enter any vowel"
read v
case $v in
[aeiou]*) echo "it is a small case"
;;
[AEIOU]*) echo "it is a capital case"
;;
*[0-9]) echo "it is a digit"
;;
esac
~
~
~
~
~
~
~
-- INSERT -- 0,1 All
E138: Can't write viminfo file /home/student/.viminfo!
Hit ENTER or type command to continue
[student@Lab1 sachin2532]$ sh vowel.sh
enter any vowel
a
it is a small case
[student@Lab1 sachin2532]$ sh vowel.sh
enter any vowel

E
it is a capital case

7
NAME:-SACHIN HARIBA METKARI
CLASS:-SYIT/B
ROLL NO:-2532
Q.8 Write a shell script for to find factorial of a number?
Ans: [student@Lab1 sachin2532]$ vi facts32_2.sh
echo "enter a number"
read a
fact=1
i=0
while [ $i -lt $a ]
do
i=` expr $i + 1`
fact=` expr $fact \* $i`
done
echo "factorial of number is"
echo $fact
~
~
~
~
~
~
~
-- INSERT -- 12,1 All
"facts32_2.sh" [New] 13L, 153C written
E138: Can't write viminfo file /home/student/.viminfo! 11,11 All
Hit ENTER or type command to continue 10,30 All
[student@Lab1 sachin2532]$ sh facts32_2.sh
enter a number
5
factorial of number is
120
[student@Lab1 sachin2532]$ sh facts32_2.sh
enter a number
4
factorial of number is
24

8
NAME:-SACHIN HARIBA METKARI
CLASS:-SYIT/B
ROLL NO:-2532
Q.9 Write a program in a shell script to check whether it is Armstrong
or not?
Ans:- [student@Lab1 sachin2532]$ vi arms2532.sh
echo "enter any number"
read num
sum=0
temp=$num

while [ $temp -ne 0 ]


do
rem=`expr $temp % 10`
c=`expr $rem \* $rem \* $rem`
sum=`expr $sum + $c`
temp=`expr $temp / 10`
done

if [ $sum -eq $num ]


then
echo "armstrong number"
else
echo "not a armstrong number"
fi
~
~
~
~
~
~
-- INSERT -- 1,1 All
E138: Can't write viminfo file /home/student/.viminfo!
Hit ENTER or type command to continue
[student@Lab1 sachin2532]$ sh arms2532.sh
enter any number
153
armstrong number
[student@Lab1 sachin2532]$ sh arms2532.sh
enter any number
67
not a armstrong number

S-ar putea să vă placă și