Você está na página 1de 20

.

Write a program using shell to input your name and


afterwards print
it:-

echo ”enter your name”


read name
echo $name

Output-

enter your name


geeta
geeta
31
Write a program to adding two numbers:- 
 

a=10

b=20

c= `expr $a +$b`

echo $c 

output-

30
 

32
Write a program to multiply two numbers:-

echo ”enter a”

read a

echo ”enter b”

read b

c= `expr $a \* $b`

echo ”multiplication is”$c

output-

enter a
10
enter b
2
multiplication is 20

 
 
 

33
Write a program to check whether a no. is even
or odd:- 
 

Echo ”enter a value”

read num

rem= `expr $num%2`

if [ $rem –eq 0 ]

then

echo”even”

else

echo”odd”

fi 

output-

enter a value

odd
34

Write a program for interchanging the value of


two variables without using a third variable:- 

a=10

b=20

echo ”intial value of a” $a

echo ”intial value of b” $b

a= `expr $a +$b`

echo ”a”

echo ”b” 

output-

intial value of a 10

intial value of b 20

20

10
 
35

Write a program for interchanging the variables


using third variable:- 
 
 
a=10

b=20

c=$a

$a=$b

$b=c

echo ”interchanging value”$a

echo ”interchanging value”$b 

output-

interchanging value 20

interchanging value 10
 
36

Write a program of Area of circle:- 


 
 
echo ”enter r”

read r

area= `expr 3.14 *$r *$r`

echo ”area”$area 
 

output-
enter r
1
area 3.14
37
Write a program of area of Circumfrance:- 
 
echo ”enter r”

read r

echo “enter p”

read p

area= `expr 2 *$*$r`

echo ”area” $area 

output-
enter r
1
enter p
2
area 4

38
Write a program to calculate Simple interest:- 
 
 echo ”enter t”
read  t,

echo ”enter r”

read  r

echo ”enter p”

read  p

si= `expr $p *$r *t/100`

echo ”answer is”$si 

output-

enter t

enter p

enter p

20000

answer is 400
39
 
Write a program to find out greater between
three variables:- 
 
 

echo ”enter a”

read a

echo ”enter b”

read b

echo ”enter c”

read c

if [ $a –gt $b –a $a –gt $c ]

then

 echo”a is greater”

elif [ $b –gt $c ]

then

echo”b is greater”

else

echo”c is greater”

fi 

output-
40
enter a

enter b

enter c

c is greater
41
Write a program to find out greater between the
two:- 
 
echo”enter a”

read a

echo”enter b”

read b

if [$a –gt $b ]

then

echo”a is greater”

else

echo”b is greater”

fi 

output-

enter a

enter b

b is greater
42
Write a program whether a no. is prime or not:-
 
echo”enter a no”

read n

x=2

y=0

while [$x –lt $n ]

do

rem=`expr $n%$n`

if [ $rem –eq 0 ]

then

y=1

fi

x=`expr $x+1`

done

if [$y –ne 1 ]

then

echo”prime”

else
43
echo”not prime”

fi 

output-

enter a no

26

not prime

44
Write a program whether a no.is palindrome or
not:- 
 
echo ”enter a no.’

read n

temp=$n

sum=0

while [ $temp –gt 0 ]

do

d=`expr $temp%10`

temp=expr $temp/10

sum=expr $sum \*10 $d

done

if [ $sum – eq $n ]

then

echo”palindrome”

elso

echo”not palindrome”

fi 
45
output-

enter a no

555

Palindrome

46
Write a program of Sum of digits:- 
 

echo”enter a no.”

read n

sum=0

while [ $n –ne 0 ]

do

d=`expr $n%10`

n=`expr $n/10`

sum=`expr $sum +$d`

done

echo”the sum is”$sum

output-

enter a no

123

the sum is 6

47

Você também pode gostar