You are on page 1of 57

V.P.M.

M ARTS AND SCIENE COLLEGE FOR WOMEN


KRISHNANKOVIL
DEPARTMENT OF COMPUTER SCIENCE
MAJOR : COMPUTER SCINCE YEAR : 2022-2023
CLASS : II BCA REG.NO :
SUB CODE:

BACHELOR OF COMPUTER APPILICATION


THIS IS CERTIFIED TO BE A BONAFIDE RECORD OF WORK DONE
BY-------------------------------------------------- SUBMITTED FOR THE PRACTICAL
EXAMINATION “LINUX PROGRAMMING LAB” AT
V.P.MUTHAIAPILLAI MEENAKSHIAMMAL ARTS AND SCIENCE
COLLEGE FOR WOMEN, KRISHNANKOVIL CONDUCTED ON-------------.

Head of the Department Staff-In-charge

Internal Examiner External Examiner


INDEX

PAGE
S.NO DATE TITLE SIGN
NO
1 SUM OF DIGITS

2 REVERSE OF A NUMBER

3 ARITHMETIC OPERATION USING CASE

4 DISPLAY MULTIPLICATION TABLE

5 PRIME NUMBER CHECKING USING WHILE

6 CASE CONVERTION USING TR

7 STRING MANIPULATION

8 PATTERN MATCHING USING GREP

9 USER LOGGED IN

10 CHECK FOR PALINDROME

11 MENU DRIVEN IMPLEMENTATION

12 STUDENT MARK LIST

13 PREPARE ELECTRICITY BILL


SETTING THE ATTRIBUTES OF A GIVEN
14
FILE
15 COMPARE TWO FILES

16 COPY AND RENAME A FILE

17 GIVEN FILE IS A DIRECTORY OR NOT

18 SORTING DATA IN A FILE

19 CHECK FOR AN ADAM NUMBER

CURRENT DATE,USER NAME AND CURRENT


20
DIRECTORY
EX.NO:1 SUM OF THE DIGITS OF A GIVEN NUMBER

DATE :

AIM:

To write a Linux program to find out the Sum of the digits for the given
number.

ALGORITHM:

 Start the process.


 Get the input value from the keyboard.
 Assign the value s=0.
 By using the while loop, we can get the result.
 Print the result on the screen.
 Stop the process.

CODING:

echo ‘ SUM OF THE DIGITS ‘

echo ‘ ------------------------ ‘

echo Enter The Value

read n

s=0

while [ $n –gt 0 ]

do
r=$((n % 10))

s=$((s + r))

n=$((n / 10))

done

echo ‘ Sum of the Digits is : ‘$s

OUTPUT:

vpmm@vpmm :~$ sh sumof

SUM OF THE DIGITS


------------------------------
Enter the value

123456789

Sum of the digits is: 45

RESULT:

Thus the program has been executed successfully and the output is shown.
EX.NO : 2 REVERSE THE NUMBER

DATE :

AIM:

To Write a Linux program to find out the Reverse the digits for the given
number.

ALGORITHM:

 Start the process.


 Get the input value from the keyboard.
 Assign the value s=0.
 By using the while loop, we can get the result.
 Print the result on the screen.
 Stop the process.

CODING:

echo ‘ REVERSE THE NUMBER ‘

echo ‘ ----------------------------- ‘

echo Enter the number

read n

s=0

while [ $n –gt 0 ]

do
r=$((n % 10))

n=$((n / 10))

s=$((s * 10 + $r))

done

echo ‘ Reverse the number is : ‘ $s

OUTPUT:

vpmm@vpmm : ~$ sh reverse

REVERSE THE NUMBER


----------------------------------
Enter the value

123456789

Reverse the Number: 987654321

RESULT:

Thus the program has been executed successfully and the output is shown.
EX.NO: 3 PERFORM BASIC ARITHMETIC OPERATION USING CASE

DATE :

AIM:

Write a Linux program to perform basic arithmetic operations using case.

ALGORITHM:

 Start the process.


 Get the input values from the keyboard one by one.
 We can choose the Choice by using the Menu of addition,
Subtraction, Multiplication, Division, and Modulus.
 By using the case, we can get the result.
 Print the result on the screen.
 Stop the process.

CODING:

echo ‘ BASIC ARITHMETIC OPERATION USING CASE ‘

echo ‘ --------------------------------------------- ‘

echo Enter the A value

read a

echo Enter the B value

read b
echo 1.Addition 2.Subtraction 3.Multiplication 4.Division 5.Modules

echo Enter ur choice

read c

case $c in

1)echo Addition :$((a + b));;

2)echo Subtraction :$((a - b ));;

3)echo multiplication : $((a * b));;

4)echo division : $((a / b));;

5)echo module : $((a % b));;

*)echo Invalid Choice

esac
OUTPUT:

vpmm@vpmm: ~ sh arithmetic

BASIC ARITHMETIC OPERATION USING CASE


-----------------------------------------------------------------------
Enter the A value: 5

Enter the B value: 3

1. Addition 2.Subtraction 3.Multiplication 4.Division 5.modulus

Enter ur choice: 3

Multiplication: 15

RESULT:

Thus the program has been executed successfully and the output is shown
EX.NO :4 DISPLAY MUTIPLICTION TABLE

DATE :

AIM:

To write a Linux program to display multiplication table

ALGORITHM:

 Start the process.


 Get the input value of Table Number and rows from the
keyboard one by one.
 Assign the value i=1.
 By using the while loop, we can get the result.
 Print the result on the screen.
 Stop the process

CODING:

echo ‘ MULTIPLICATION TABLE ‘

echo ‘ ----------------- ‘

echo ‘ Enter Table Number ‘

read tn

echo ‘ Enter How Many Rows U Need : ‘

read n

i=1
while [$i –le $n ]

do

k=$((i *tn))

echo “ $i * $tn = $k “

i=$((i+1))

done

OUTPUT:

vpmm@vpmm:~ sh multab

MULTIPLICATION TABLE
---------------------------------------
Enter Table Number: 5
Enter How Many Rows U Need: 5

1*5=5

2 * 5 = 10

3 * 5 = 15

4 * 5 = 20

5 * 5 =25

RESULT:

Thus the program has been executed successfully and the output is
shown.
EX.NO:5 CHECK WHETHER A NUMBER IS PRIME OR NOT USING
WHILE

DATE:

AIM:

To Write a Linux program to check whether the given number is prime or not
using while.

ALGORITHM:

 Start the process.


 Get the input value from the keyboard.
 Assign the value i=2 and f=0.
 By using the while loop, we can get the result.
 If equals to zero then print given number is prime else given
number is not prime.
 Stop the process
CODING:

echo ‘ CHECK WHETHER THE GIVEN NUMBER IS PRIME OR NOT’

echo ‘ ----------------------------------------------------------------------------------‘

echo ‘ Enter the number ‘

read n

i=2

f=0

while test $i –le `expr $n / 2`

do

if test `expr $n % $i` -eq 0

then

f=1

fi

i=`expr $i + 1`

done

if test $f –eq 0

then

echo ‘ Given Number is Prime ‘

else

echo ‘ Given Number is not Prime ‘

fi
OUTPUT:

CHECK WHETHER THE GIVEN NUMBER IS PRIME OR NOT


-------------------------------------------------------------------------------------
Enter the Number: 3

Given Number is Prime

CHECK WHETHER THE GIVEN NUMBER IS PRIME OR NOT


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

Enter the Number: 4

Given Number is Not Prime

RESULT:

Thus the program has been executed successfully and the output is shown.
EX.NO: 6 CONVERT LOWERCASE TO UPPERRCASE USING TR

DATE :

AIM:

To write a Linux program to Lowercase to Uppercase using TR Statement.

ALGORITHM:

 Start the process


 Get the input value from the keyboard.
 Already we wrote a file named as names.
 By using the tr statement, we can get the result.
 Print the result on the screen.
 Stop the process.

CODING

getFile()

echo –n “Enter File Name:”

read upper

if [ ! –f $upper ]; then

echo “File Name $upper does not exists.”

Exit 1

fi

}
clear

echo “1. Uppercase to Lowercase “

echo “2.Lowercase to Uppercase “

echo “3.exit “

echo –n “Enter your choice(1-3):”

read Ch

case “$Ch” in

1)

getFile

echo “Converting Upper-case to Lower-Case “

echo “ ------------------------------------------------ “

tr ‘[A-Z]’ ‘[a-z]’ <$upper

;;

2)

getFile

echo “Converting Lower-Case to Upper-Case “

echo “ --------------------------------------------- “

tr ‘[a-z]’ ‘[A-Z]’ <$upper

;;

*)echo “Exiting…”

exit

;;

esac
OUTPUT:

1.Uppercase to Lowercase

2.Lowercase to Uppercase

3.Exit

Enter Your Choice (1-3):2

Enter File Name: Upper

Converting Upper-case to Lower-case


---------------------------------------------
Preethi
Preethi

Enter Your Choice (1-3):2

Enter File Name: Upper

Converting Lower-case to Upper-case


------------------------------------------------
PREETHI
PREETHI

Enter your Choice (1-3):3

Enter File Name: Upper

Existing…

RESULT:

Thus the program has been executed successfully and the output is shown.
EX.NO:7 PERFORM STRING MANIPULATION

DATE:

AIM:

To write a Linux program to perform string manipulation.

ALGORITHM:

 Start the process.


 Get the input file String from the keyboard.
 We have to find the length of the string by using the command as wc-c
 We have to find the reverse the string by using while loop with
necessary commands.
 Print the result on the screen.
 Stop the process.

CODING:

echo ‘ STRING MANIPULATION ‘

echo ‘ --------------------- ‘

echo ‘ Enter the string ‘

read s

len= `echo $s | wc –c `

echo ‘ Length of the Given String is :’ $len

while [ $len –ge 1 ]

do
temp=`echo $s | cut –c $ln`

rev=`echo $rev $temp`

len=`expr $len -1`

done

echo ‘ Reverse the String is : ‘ $rev

OUTPUT:

vpmm@vpmm:~ sh manip

STRING MANIPULATION
-----------------------------------
Enter the String :
Anjanaria

Length of the Given String is: 10

Reverse the string is: a i r a n a j n A

RESULT:

Thus the program has been executed successfully and the output is shown.
EX.NO:8 PATTERN MATCHING USING GREP COMMAND

DATE:

AIM:

To write a Linux program to check pattern matching using grep command

ALGORITHM:

 Start the process.

 Get the input value of pattern and file name from the keyboard.

 We can use the Grep command as $pn and $names.

 We can the Cat command as $names to shown the desired pattern on

the screen.

 Print he result on the screen.

 Stop the process.


CODING:

echo ‘ PATTERN MATCHING ‘

echo ‘ --------------------- ‘

echo ‘ Enter the pattern to be search : ‘

read pn

echo ‘ Enter the File Name : ‘

read names

echo ‘ selected as pn from the File name of names : ‘

grep $pn $names

echo

echo ‘ Selected Record from the Database ‘

cat $names

names

anu

koppu

malli

muni

shobi

suji
OUTPUT:

vpmm@vpmm:~$ sh pattern

PATTERN MATCHING
-------------------------------
Enter the pattern to be Search: Malli
Enter the File Name: Name

Selected as pn from the file name of names:

Selected record from the database

Anu

Koppu

Malli

Muni

Shobi

suji

RESULT:

Thus the program has been executed successfully and the output is shown.
EX.NO:9 FIND THE NUMBER OF USER WHO HAVE LOGGED IN

DATE:

AIM:

To write a Linux program to find the number of user who have logged in.

ALGORITHM:

 Start the process.

 Get the input value of the number of user entered through the

keyboard by using the who and wc command.

 We can show which users the first one to enter into the system.

 Print the result on the screen.

 Stop the process.

CODING:

echo ‘ LOGIN USER ;

echo ‘ --------- ‘

echo ‘ The Number of User Login are : ‘

who | wc -1

echo First Login User

who | head -1
OUTPUT:

vpmm@vpmm:~$ sh login

LODIN USER
------------------
The Number of user Login are: 2

First Login User

vpmm: 0 2021-03-12 05:37-(:0)

RESULT:

Thus the program has been executed successfully and the output is shown.
EX.NO:10 CHECK FOR PALINDROME

DATE :

AIM:

To write a Linux program to check whether the given number is


Palindrome or not.

ALGORITHM:

 Start the process.

 Get the input value from the keyboard.

 Assign the value of x=$n and s=0.

 We can get the result of s by using the while loop.

 If $s equals to $x then print the given number is palindrome else

given number is not palindrome.

 Stop the process.


CODING:

echo ‘THE GIVEN NUMBER IS PALINDROME OR NOT’

echo ‘ ----------------------------------------------------------------- ‘

echo Enter the number

read n

x=$n

s=0

while [$n –gt 0 ]

do

r=$((n%10))

s=$((s\*10+r))

n=$(($n/10))

done

if [ $s –eq $x ]

then

echo ‘ Given Number is Palindrome ‘

else

echo ‘ Given Number is Not Palindrome ‘

fi
OUTPUT:

vpmm@vpmm:~$ sh palind

GIVEN NUMBER IS PALINDROME OR NOT


------------------------------------------------------------
Enter the number

151

Given number is palindrome

vpmm@vpmm:~$ sh palind

GIVEN NUMBER IS PALINDROME OR NOT


------------------------------------------------------------
Enter the number
143

Given number is not palindrome

RESULT:

Thus the program has been executed successfully and the output is shown.
EX.NO:11 MENU DRIVEN IMPLEMENTATION

DATE :

AIM:

To write a Linux program to create a menu driven implementation for


accessing some result through the keyboard.

ALGORITHM:

 Start the process,

 Create a menu for accessing some information through the

keyboard.

 Enter the choice one by one from the keyboard by using case.

 We can use the data ,ps ,who and Is -1 command for getting the

desired result on the screen.

 Print the result on the screen one by one

 Stop the process.


CODING:-

echo ‘ MENU DRIVEN IMPLEMENTATION ‘

echo ‘ ----------------------------- ‘

echo ‘ 1.Today DATA 2.Processing the system 3.User of the System 4.List of the
Files ‘

echo ‘ Enter Ur Choice ‘

read c

case $c in

1)data;

2)ps;;

3)who;;

4)Is – 1;;

*)echi Invalid case

esac

OUTPUT:

vpmm@vpmm:~$ sh driven

MENU IMPLEMENTATION
--------------------------------------
1. Today DATE 2.Processing the System 3.Users of the system

4. List of Files
Enter Ur choice:

Fri Mar 12 06:20:21 IST 2021.

vpmm@vpmm:~$ sh driven

MENU IMPLEMENTATION
----------------------------------------
1. Today date 2.Processing the system 3.Users of the system 4.List of Files

Enter Ur choice:

PID TTY TIME CMD

2712 pts/0 00:00:00 bash

2726 pts/0 00:00:00 sh

2727 pts/0 00:00:00 ps

vpmm@vpmm:~$ sh driven

MENU IMPLEMENTATION
--------------------------------------
1. Today date 2.Processing the System 3.Users of the System 4.List of Files
Enter Ur choice:

rajeshkumar:0 2021-03-12 05:37 (:0)

rajeshkumar pts/0 2021-03-12 03:20 (:0)


rajeshkumar@rajeshkumar:~$ sh driven
MENU IMPLEMENTATION
--------------------------------------
1.Today date 2.Processing the System 3.Users of the system 4.List of Files

Enter Ur choice:

ls: cannot access -: No such file or directory

ls: cannot access l: No such file or directory

rajeshkumar@rajeshkumar:~$

RESULT:

Thus the program has been executed successfully and the output is shown.

EX.NO:12 GET MARK DETAILS OF A STUDENT AND DISPLAY


TOTAL AND GRADE
DATE :

AIM:

To write a Linux program to get mark details of a student and display total
and grade.

ALGORITHM:

 Start the process.


 Get the input value of student name, register number, mark1,
mark2, mark3, mark4, mark5 on the keyboard.
 We can find out the total, average, result and grade.
 We can find out the result by using the formula one by one.
 Print the result on the screen one by one.
 Stop the process.

CODING:

echo ‘ STUDENT MARK LIST ‘

echo ‘ ----------------------- ‘

echo ‘ Student Name : ‘

read name

echo ‘ Register Number : ‘

read rno

echo ‘ Mark 1 : ‘
read m1

echo ‘ Mark 2 : ‘

read m2

echo ‘ Mark 3 : ‘

read m3

echo ‘ Mark 4 : ‘

read m4

echo ‘ Mark 5 : ‘

read m5

tot= $(expr $m1 + $m2 + $m3 + $m4 +$m5)

avg=$(expr $tot / 5)

echo ‘ Student Mark List ‘

echo ‘ --------------------- ‘

echo “Student Name : $name”

echo “Register Number :$rno”

echo”Mark1 :$m1”

echo”Mark2 :$m2”

echo”Mark3 :$m3”

echo”Mark4 :$m4”

echo”Mark5 :$m5”

echo”Total :$tot”

echo”Average :$avg”
if [ $m1 –ge 35 ] && [ $m2 –ge 35 ] && [ $m3 –ge 35 ] && [ $m4 –ge 35 ] && [
$m5 –ge 35 ]

then

echo “ Result : pass”

if [ $avg –ge 90 ]

then

echo “ Grade :S”

elif [ $avg –ge 80 ]

then

echo “ Grade :A”

elif [ $avg –ge 70 ]

then

echo “ Grade :B”

elif [ $avg –ge 60 ]

then

echo “ Grade :C”

elif [ $avg –ge 50 ]

then

echo “ Grade :D”

elif [ $avg –ge 35 ]

then

echo “Grade :E”

fi
else

echo “Result :Fail”

fi

OUTPUT:

vpmm@vpmm:~$ sh mark

Student Mark List


----------------------
Student Name :Anjana

Register Number :14301

Mark1 : 65

Mark2 : 75

Mark3 : 85

Mark4 : 76

Mark5 : 87

Total : 388

Average : 77

Result : pass

Grade :B

RESULT:

Thus the program has been executed successfully and the output is shown.

EX.NO:13 PREPARE ELECTRICITY BILL


DATE :

AIM:

To write a Linux program to prepare electricity bill.

ALGORITHM:

 Start the process.

 Get the input values of consumer name, consumer number, current

month reading, last month reading from the keyboard.

 We can find out the consumed unit and its total price by using the

formula.

 Print the result on the screen with entire details.

 Stop the process.

CODING:

echo ‘ PREPARE ELECTRICITY BILL ‘

echo ‘ ---------------------- ‘

echo ‘ Consumer Name ‘

read name

echo ‘ Consumer Number ‘


read mno

echo ‘ Current Month Reading ‘

read cmr

echo ‘ Last Month Reading ‘

read lmr

unit=${expr $cmr - $lmr)

if [ $unit –eq 0 ]

then

charge=40

elif [ $unit –gt 0 ] && [ $unit –ge 100 ]

then

charge=$(expr $unit \* 1)

elif [ $unit –gt 100 ] && [ $unit –le 300 ]

then

charge=$(expr 100 \* 1 + $unit – 100)

elif [ $unit –gt 300 ] && [ $unit –le 500 ]

then

charge=$(expr $unit \* 1 + 200 \* 2 + $unit – 300)

elif [ $unit –gt 500 ]

then

charge=$(expr 1400 + $unit - 400)

fi

echo ‘ Electricity Bill ‘


echo ‘ ----------------- ‘

echo “Consumer Name :$name”

echo “Consumer Number :$mno”

echo “Current Month Reading :$cmr”

echo “Last Month Reading :$lmr”

echo”Unit :$unit”

echo “Charge :$charge”

OUTPUT:

vpmm@vpmm :~$ sh ebbill

PREPARE ELECTRICITY BILL


----------------------------------------
Consumer Name : Laxmi

Consumer Number : RK14301

Current Month Reading : 456

Last Month Reading : 123

Electricity Bill
-------------------
Consumer Name : Laxmi

Consumer Number : RK14301

Current Month Reading : 456

Last Month Reading : 123

Unit : 333

Charge : 766

RESULT:

Thus the program has been executed successfully and the output is shown.

EX.NO:14 SETTING THE ATTRIBUTES OF A GIVEN FILE


DATE :

AIM:

To write a Linux program to set the attributes of given files.

ALGORITHM:

 Start the process.

 Get the input file name from the keyboard.

 We have to check whether successfully run mode attributes was set

for file or not.

 If the condition has been satisfied then print attributes was set for file

else print attributes was not for file

 Stop the process.

CODING

echo ‘ SEETING THE ATTRIBUTES OF A GIVEN FILE ‘

echo ‘ -------------------------------------- ‘

echo ‘ Name of the File : ‘

read fn

if chmod +x $fn

then
echo ‘ Successfully Run Mode Attributes was set for files ‘

else

echo ‘ Attributes was not set for File ‘

fi

bye

echo ‘ Welcome to My Home ‘

OUTPUT:

vpmm@vpmm :~$ sh attributes

SETTING THE ATTRIBUTES OF A GIVEN FILE


-----------------------------------------------------------------
Name of the File : bye
Successfully Run Mode Attributes was set for File

RESULT:

Thus the program was has been executed successfully and the output is
shown.

EX.NO:15 COMPARE TWO FILES


DATE:

AIM:

To write a Linux program to compare two files.

ALGORITHM:

 Start the process.

 Get the two input file names one by one from the keyboard.

 We have to compare both files names by using the condition.

 If the condition has been satisfied then print both files are same else

print both files are differ.

 Stop the process.

CODING:

echo ‘ COMPARE TWO FILES ‘

echo ‘ ------------------------------- ‘

echo ‘ First Files Name : ‘

read f1

echo ‘ Second Files Name : ‘


read f2

if cmp $f1 $f2

then

echo ‘ Both Files are Same ‘

else

echo ‘ Both Files are Differ ‘

fi

hai

echo ‘ Welcome to My Heart ‘

bye

echo ‘ Welcome to My Home ‘

OUTPUT:
vpmm@vpmm :~ $ sh compare

COMPARE TWO FILES


-------------------------------
First File Name: Hai

Second File Name: Bye

Hai bye differ : byte 27 , line 1

Both Files are Differ

RESULT:

Thus the program has been executed successfully and the output is shown.

EX.NO:16 COPY AND RENAME A FILE


DATE :

AIM:

To write a Linux program of copy a file using cp command.

ALGORITHM:

 Start the process.

 Get the input file from the keyboard.

 Copy a source file to a target file using cp command

 Rename a source file to a target file using mv command.

 Print the result on the screen.

 Stop the process.

CODING:
echo ‘ COPY AND RENAME A FILE ‘

echo ‘ --------------------------------- ‘

echo ‘ Enter and Exiting by the File Name ‘

read f1

echo ‘ Enter a new File Name ‘

read f2

cp $f1 $f2

echo ‘ File Copied ‘

ls

echo ‘ Enter a new File Name ‘

read f3

mv $f2 $f3

echo ‘ File Renamed ‘

ls

OUTPUT:
vpmm@vpmm- thinkpad-R61:~$ sh cfrf

COPY AND RENAME A FILE


--------------------------------------
Enter and Exiting by the File Name

Cfrf

Enter a New File Name

raj

File copied

Attri desktop -downloads login raj user videos

Attri~ disrev -examples.desktop music rk user~

Cfrf disrev lcuc picture summa users

Enter a new File Name

rya

File Renamed

Attri desktop download login~ rk user videos

Attri disrev example.desktop music rya user~

Cfrf disrev lcuc pictures summa users

RESULT:

Thus the program has been executed successfully and the output is shown

EX.NO:17 CHECK THE GIVEN FILE IS A DIRECTORY OR NOT


DATE :

AIM:

To write a Linux program to the given file is a directory or not.

ALGORITHM:

 Start the process.

 Get the input file name from the keyboard.

 We have to check whether the directory is found or not by

using the condition.

 If the condition has been satisfied then print directory is found

else directory is not found.

 Stop the process.

CODING:

echo ‘ CHECK THE GIVEN FILE IS A DIRECTORY OR NOT ‘

echo ‘ --------------------------------------------------------- ‘

echo ‘ Enter the File Name : ‘

read fname
if [ -d $fname ]

then

echo ‘ It is a Directory ‘

else

echo ‘ It is not a Directory ‘

fi

OUTPUT:

rajeshkumar@rajeshkumar :~ $ sh direct

CHECK THE GIVEN FILE IS A DIRECTORY OR NOT

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

Enter the File Name: direct

It is not a Directory

RESULT:

Thus the program has been executed successfully and the output is shown.

EX.NO:18 ASCENDING AND DESCENDING ORDER


DATE :

AIM:

To write a Linux program to read 5 names from a file and sort in ascending
and descending order.

ALGORITHM:

 Start the process,

 Get the input value from the keyboard.

 We can create another one file that contains 10 names in any order.

 We can use the sort and cat command to show the desired results on

the screen such as ascending and descending order.

 Print the result on the screen.

 Stop the process

CODING:
echo ‘ ASCENDING OREDR & DESCENDING ORDER USING 5 NAMES ‘

echo ‘ -------------------------------------------------------- ‘

echo ‘ Enter the File Name Containing Names ‘

read name

sort –g $name > name_asce

sort –g $name > name_desc

echo ‘ List of Ascending Order : ‘

cat name_asce

echo ‘ List of Descending Order : ‘

cat name_desc

names

anu

koppu

malli

muni

shobi

OUTPUT:
rajeshkumar@rajeshkumar : ~ $ sh ascen

ASCENDING ORDER & DESCENDING ORDER USING 5 NAMES

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

Enter the file name Containing Names: Names

List of ascending order:

Anu

Koppu

Malli

Muni

Shobi

List of Descending Order:

Shobi

Muni

Malli

Koppu

anu

RESULT:

Thus the program has been executed successfully and output shown.

EX.NO:19 ADAM NUMBER


DATE :

AIM:

To write a Linux program of given number is Adam or not.

ALGORITHM:

 Start the process.

 Get the input value from the keyboard.

 We have to find the square of the given number n as n2

 Reverse the given number of n by using while loop.

 Now, we have to square the reversed number.

 Again, we have to reverse the squared number.

 If both are equal, the print given number is Adam else given number is

not Adam.

 Stop the process.


CODING:

echo ‘ CHECK WHETHER THE GIVEN NUMBER IS ADAM OR NOT ‘

echo ‘ ------------------------------------------- ‘

echio ‘ Enter the Number : ‘

read num

sq=’ expr $num \* $num

echo =”Square of given number: “$ sq

rev=0

while test $sq –gt 0

do

d=’expr $sq % 10’

rev=’expr $rev \* 10+%d’

sq=’expr $sq / 10’

done

echo”Reverse of the square number:”$rev

rev 1=0

while test $ num –gt 0

do

d1=’expr $ num % 10’

rev 1=’expr $ rev 1 \* 10 +$ d1’

num=’expr $ num / 10’

echo “Reverse of given number:”$ rev 1

sq 1=’expr $ num \* rev 1’


echo “Square of reverse number:”$ sq 1

if test $ rev –eq $sq 1

then

echo “Given number is Adam Number”

else

echo “Given Number is not Adam number”

fi

OUTPUT:

ADAM NUMBER
_________________
Enter the Number:13

Square of given number:169

Reverse of the square number:961

Reverse of given number:31

Square of given number:961

Given number is Adam number.

RESULT:

Thus the program has been executed successfully.


EX.NO:20 CURRENT DATA, USER NAME AND CURRENT
DIRECTORY

DATE:

AIM:

To write a Linux program to print current data, user name and current
directory.

ALGORITHM:

 Start the process.

 Get the input file name from the keyboard.

 We have to check whether the directory is found or not by using the

condition.

 If the condition has been satisfied then print directory is found else

directory is not found.

 Stop the process.


CODING:

echo ‘CURRENT DATA, USEER NNAME AND DIRECTORY’

echo’-----------------------------------------------------------------------‘

echo”hello $LOGNAME”

echo”current date is ‘date’”

echo”current Directory’pwd’”

OUTPUT:

Current data, user Name and directory


---------------------------------------------
Hello user 1
Current date is the mar22 06:50:07 IST 2001

Current Directory tome/user1

RESULT:

Thus the program has been executed successfully and the result is shown.

You might also like