Mewar University, Chittorgarh
M.Tech. 1st Semester
List of Program:
Prog 1: WAP to print diagonal matrix.
Prog 2: WAP to sort an array using bubble sort.
Prog 3: WAP to sort an array using insertion sort.
Prog 4: WAP to sort an array using selection sort.
Prog 5: WAP to convert lower-case sentence in to uppercase sentence.
Prog 6: WAP to calculate area of triangle.
Prog 7: WAP to print a diamond of stars (*).
Prog 8: WAP to convert decimal into Octal and Hexa Decimal.
Prog 9: Write a shell program to find the average of students marks using for loop and
while loop.
Prog10: Write a shell script to compute all arithmetic operations on which are given by
user.
Prog 11: Write a shell program to find the average of students marks using for loop and
while loop.
Prog12: Write a shell program to convert temperature in centigrade to Fahrenheit.
Prog13: Write a shell script to find the area of the triangle.
Prog14: Write a shell script that accepts a file name starting and line number as
arguments and display all line.
Prog15: Write a shell script to print months of a year using switch case.
Prog16: Write a shell script that accept two integers as its argument and computes the
value of first number raised to the power of the second number.
Write a shell script that accepts a file name starting and ending numbers as Arguments and
displays all the lines between the given line numbers.
Shell Script
#!/bin/csh
head -$argv[3] $argv[1] | tail -n $argv[2]
--------------------------------------------------------------
Write a shell script that accepts two integers as its arguments and computes the value of first
number raised to the power of the second number.
Shell Script
#!/bin/csh
set c = 1
set result = 1
while($c <= $argv[2])
@ result *= $argv[1]
@ c = $c + 1
end
echo "$argv[1] raised to the power of $argv[2]=$result"
--------------------------------------------------------------
Write a shell program to convert temperature in centigrade to Fahrenheit.
Shell Script
echo "Converting between the different temperature scales"
echo "1. Convert Celsius temperature into Fahrenheit"
echo "2. Convert Fahrenheit temperatures into Celsius"
echo -n "Select your choice (1-2) : "
read choice
if [ $choice -eq 1 ]
then
echo -n "Enter temperature (C) : "
read tc
# formula Tf=(9/5)*Tc+32
tf=$(echo "scale=2;((9/5) * $tc) + 32" |bc)
echo "$tc C = $tf F"
elif [ $choice -eq 2 ]
then
echo -n "Enter temperature (F) : "
read tf
# formula Tc=(5/9)*(Tf-32)
tc=$(echo "scale=2;(5/9)*($tf-32)"|bc)
echo "$tf = $tc"
else
echo "Please select 1 or 2 only"
exit 1
fi
--------------------------------------------------------------
Write a shell program to find the average of students’ marks
Shell Script
for i in $*
do
temp_total=`expr $temp_total + $i`
done
avg=`expr $temp_total / $number_of_args`
echo "Average of all marks is $avg"
--------------------------------------------------------------
Write a shell script to find the area of the triangle
Shell Script
echo -n "Enter base of a triangle : "
read b
echo -n "Enter height of a triangle : "
read h
# calculates it and display back
area=$(echo "scale=2;(1/2) * $b * $h"|bc)
echo "Area of a triangle is $area"
a=$1
op="$2"
b=$3
--------------------------------------------------------------
Write a shell script to compute all arithmetic operations on which are given by user.
Shell Script
if [ $# -lt 3 ]
then
echo "$0 num1 opr num2"
echo "opr can be +, -, / , x"
exit 1
fi
case "$op" in
+) echo $(( $a + $b ));;
-) echo $(( $a - $b ));;
/) echo $(( $a / $b ));;
x) echo $(( $a * $b ));;
*) echo "Error ";;
esac
--------------------------------------------------------------
Write a shell script that accepts two integers as its arguments and computes the value of first
number raised to the power of the second number.
Shell Script
#!/bin/csh
set c = 1
set result = 1
while($c <= $argv[2])
@ result *= $argv[1]
@ c = $c + 1
end
echo "$argv[1] raised to the power of $argv[2]=$result