0% found this document useful (0 votes)
9 views2 pages

Ex 3 A

The document contains shell scripts for basic programming exercises, including swapping two numbers, performing arithmetic operations, calculating the area and circumference of a circle, and converting Celsius to Fahrenheit. Each section provides user prompts for input and displays the results of the operations. Sample outputs are included to demonstrate the functionality of each script.

Uploaded by

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

Ex 3 A

The document contains shell scripts for basic programming exercises, including swapping two numbers, performing arithmetic operations, calculating the area and circumference of a circle, and converting Celsius to Fahrenheit. Each section provides user prompts for input and displays the results of the operations. Sample outputs are included to demonstrate the functionality of each script.

Uploaded by

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

Ex No-3a SHELL PROGRAMS(BASIC)

--------------------------------

//SWAPPING OF TWO NUMBERS

echo "Enter two numbers to swap : "


read a
read b
temp=$a
a=$b
b=$temp
echo "After swapping "
echo $a
echo $b

[******@telnet ~]$ sh swap.sh


Enter two numbers to swap :
5
9
After swapping
9
5

//ARITHMETIC FUNCTION

echo "Enter 1st num: "


read a
echo "Enter 2nd num: "
read b
c=`expr $a + $b`
echo "Sum: $c"
c=`expr $a - $b`
echo "Diff: $c"
c=`expr $a \* $b`
echo "Mul: $c"
c=`expr $a / $b`
echo "Div: $c"
c=`expr $a % $b`
echo "modulus: $c"

[******@telnet ~]$ sh arith.sh


Enter 1st num:
5
Enter 2nd num:
7
Sum: 12
Diff: -2
Mul: 35
Div: 0
modulus: 5

//AREA AND CIRCUMFERENCE

echo "Enter radius: "


read r
a=`expr "scale=2; $r * $r * 3.14"|bc`
echo "area: $a"
c=`expr "scale=2;$r * 2 * 3.14"|bc`
echo "circumference: $c"

[******@telnet ~]$ sh area.sh


Enter radius:
5
area:78.50
circumference: 31.40

//TEMPERATURE CONVERSION

echo "Enter celsius temp:"


read c
f=`echo $c \* 1.8 +32 |bc`
echo "Fahrenheit temp : $f"

[******@telnet ~]$ sh temp.sh


Enter celsius temp:
45
Fahrenheit temp : 113.0

You might also like