You are on page 1of 45

GE2155 COMPUTER PRACTICE

LABORATORY-II
LAB MANUAL
,
ASSISTANT PROFESSOR,
DEPARTMENT OF CSE,
R.M.K.C.E.T, PUDUVOYAL-601 206.
1
Ex.NO:1 STUDY OF UNI OS
INTRODUCTION
An operating system is software that acts as an interface between the user and the
computer hardware. It is considered as the brain of the computer. It controls and co-ordinates
the internal activities of the computer and provides user interface.
The computer system is built with the following general components
i) Hardware
ii) Application Software
iii) Operating System
(i) !"#$%"#&: This includes the physical components such as !"# $eyboard# Hard
dis% and !rinter.
(ii) A''()*"+),- S,.+%"#&: These are the programs that are used to accomplish specific
tas%s.
(iii)O'&#"+)-/ S01+&2: It is the component or the set of programs to manage and control
the hardware as well as co-ordinate the applications. &ach system must have at
least have the hardware and the OS.
Manage Application
Manage Hardware
Spread Sheet
'ord !rocessor
&-mail
( )om *onitor (is%
!" $eyboard !rinter
+ame
Applicatio
n
Operating
System
Hardware
F3-*+),-1 ,. "- O'&#"+)-/ S01+&2
C,22"-$ )-+&#'#&+"+),-: The !" can,t understand the commands %eyed in by a
user. It is the function of the OS to ma%e it understand.
P&#)'4&#"( I-+&#."*&1: The OS also has to ta%e care of the devices attached to the
system. The OS oversees communication between these devices and the !".
M&2,#0 2"-"/&2&-+: The OS handles the e-tremely important .ob of allocating
memory for various processes running on the system.
P#,*&11 2"-"/&2&-+: This is re/uired if several programs must run concurrently.
!" time would then have to be )ationed out by the OS to ensure that no programs
gets more than its fair share of the processor time.
S&#5)*&1 ,. "- OS:
0. !rocess *anagement
1. 2ile *anagement
3. I4O *anagement
5. Scheduling
6. Security *anagement
UNI OPERARTING SYSTEM:
In the mid-0789s# AT :T ;ell <aboratories developed a new OS called *ultics.
*ultics was intended to supply large scale computing services as a utility= much li%e
electrical power. In 0787 $en Thompson# (ennis )itchie and others developed and simulated
an initial design for a file system that later evolved into the ">I? file system. The whole
">I? was rewritten in @, language in 07A3.Today# ">I? is a giant Os and is much
powerful than most of its counter parts.
">I? operating System is li%e a layer between the hardware and the applications that
run on the computer .It has functions that run on the computer. It has functions that manage
the e-ecuting applications.
">I? system is an OS# which includes the traditional system components. ">I? system
includes a set of libraries and a set of applications.
$&)>&< is the heart of ">I? OS that manages the hardware and the e-ecuting
process. The ">I? system views each device as a file called a device file. It implements
security controls to protect the safety and privacy of information. The "ni- System allocates
resources including use of the !" and mediates accesses to the hardware.
Application portability is the ability of a single application to be e-ecuted on various
types of computer hardware without being modified. This is one of the important advantages
of ">I?.
FEATURES OF UNI:
1. M3(+)+"16)-/
Other Applications
Standard Application
Standard Libraries
File System Process
control
Hardware
fopen
()
for% B )
U!"
*ultitas%ing is the capability of the Os to perform various tas%s simultaneously. i.e. A
single user can run multiple programs concurrently.
2. M3(+)31&# C"'"7)()+0
*ultiuser capability allows several users to use the same computer to perform their
tas%s. Several terminals are connected to a single powerful computer and each user can
wor% with their terminals.
8. S&*3#)+0
"ni- allows sharing of data. &very user must have a <ogin name and a password. So#
accessing another user,s data is impossible without permission.
9. P,#+"7)()+0
"ni- is a portable because it is written in high level languages so it can run on
different computers.
5. C,223-)*"+),-
"ni- supports communication between different terminals connected to the "ni-
server and also between the users of one computer to the users of another computer
located elsewhere in the networ%.
6. P#,/#"22)-/ F"*)()+0
"ni- is highly programmable# the "ni- shell programming language has the
conditional statements and control structures and variables.
UNI ARC!ITECTURE
The functioning of "ni- OS is handled in 3 ways. The closest layer is the hardware#
which provides the services to the OS. The "ni- OS referred to "ni- as the %ernel# is the
heart of the "ni-. The other layer is the shell# which acts as the mediator that translates the
commands given by the application programs.
K&#-&(
It is the core of the OS. It controls all the tas%s and carries out all the functions of an
OS such as memory and file management etc.# and it %eep trac% of the programs that are
e-ecuting. It also handles the information e-change between the terminals such as tape drives
and printers etc.#
F3-*+),-1 ,. K&#-&(
1. Allocating and deallocating memory to each and every process.
2. )eceiving instructions from the shell and carrying them out.
8. *anaging files that held on various storage devices.
9. Scheduling# oordinating and assigning various input4output devices
simulataneously.
5. &nforcing security measures.
6. !roviding >etwor% services.
:. !roviding "tility services.
;. oordinating each and every process with signal handling.
<. !roviding administrative functions or utilities.
S4&((
It is the command interpreter of the OS. The commands given from the user are
moved to the shell. The shell analyses and interprets these commands into the machine
understandable form. The commands can be either typed in through the command line or
hardwar
e
contained in a file called shell script. Hence# Shell acts as an interface between the user and
the %ernel.
">I? has a variety of shells# they areC
(i) B,3#-& S4&((: It is developed by Steve ;ourne and it is the most popular shell
and widely used. This shell comes bundled with almost every "ni- system.
(ii) K,#- 14&((: It is developed by (avid +.$orn. This is superset of ;ourne shell
an
it has more capabilities.
(iii) C S4&((: It is developed by ;il Doy. It is similar to !rogramming language.
F&"+3#&1 ,. S4&((
0. All communications between user and $ernel ta%es place through the shell.
1. It allows the tas%s to run on bac%ground.
3. It also enables us to construct scripts li%e a programming language.
5. A group of files can be e-ecuted using a single command.
S+"#+)-/ " UNI 1&11),- = L,//)-/ I-
A user of "ni- based system wor%s as a user terminal. After the boot procedure is
completed# that is the operating system is loaded in memory# the following message appears
at each user terminalC
L,//)-/
&ach user has a identification called the user name are the login name which has to be
entered when the loginC message appears. The user is then as%ed to enter the password. "ni-
%eeps trac% of all the "ni- user names and the information about identity in a special file. If
the login name entered does not match with any of the user names it displays the login
message again. This ensures that# only authoriEed people use the system. 'hen a valid user
name is entered at the terminal the dollar symbol is displayed on the screen this is the "ni-
prompt.
E-$)-/ " UNI 1&11),- =L,//)-/ O3+
Once a user has logged into the system the users wor%s session continues until the
user instructs the shell to terminate the session. This is done by pressing the ctrl and @d %eys,
together or typing e-it at the dollar prompt. Then the systems display the loginC
!rompt on the screen#
Ex.NO:2 BASIC UNI COMMANDS
A)2
To Study about basic "ni- ommands.
FILE MANIPULATION COMMANDS
C,22"-$ : at
P3#',1& : It is used to display the contents of the file as well as used to create a new
file.
S0-+"x : *"+ >.)(& -"2& ?
Ex"2'(& : F cat devi
C,22"-$ : *ore
P3#',1& : It is used to display the contents of the file on the screen at a time.
S0-+"x : 2,#& >.)(& -"2& ?
Ex"2'(& : F more devi
C,22"-$ : 'c
P3#',1& : It is used to count the number of lines #words and characters in a file or
group of files.
S0-+"x : %* @,'+),-1A >.)(& -"2& ?
Ex"2'(& : F wc Gl devi
C,22"-$ : 2ile
P3#',1& : It is used to determine the type of the file.
S0-+"x : .)(& >.)(& -"2& ?
Ex"2'(& : F file devi
C,22"-$ : Spell
P3#',1& : It is used to find the spelling errors in the file.
S0-+"x : 1'&(( @,'+),-1A >.)(& -"2& ?
Ex"2'(& : F spell -b devi
C,22"-$ : Split
P3#',1& : It is used to split the given file into smaller pieces of given siEe.
S0-+"x C 1'()+ =1)B& >.)(& -"2& ? > 1'()++&$ .)(& -"2& ?
Ex"2'(& : F split G1 devi de
C,22"-$ : p
P3#',1& : It is used to copy one or more files.
S0-+"x : *"+ >1,3#*& .)(& -"2& ? >$&1+)-"+),- .)(& -"2&?
Ex"2'(& : F cp devi latha
C,22"-$ : *v
P3#',1& : It is used to move a file within a directory with different names and also
used to move a file to different directory with its original name.
S0-+"x : 25 >1,3#*& .)(& -"2& ? >$&1+)-"+),- .)(& -"2&?
Ex"2'(& : F mv devi .eya
C,22"-$ : )m
P3#',1& : It is used to remove a file from the dis%.
S0-+"x : #2 >.)(& -"2& ?
Ex"2'(& : F rm devi
GENERAL PURPOSE COMMANDS
C,22"-$ : ;anner
P3#',1& : It is used to display its argument in large letters.
S0-+"x : 7"--&# > 1+#)-/ ?
Ex"2'(& : F banner ;OO*
C,22"-$ : 'ho
P3#',1& : It is used to get the information about all the users currently wor%ing in
the system.
S0-+"x : %4,
Ex"2'(& : F who
C,22"-$ : 'ho am i
P3#',1& : It is used to %now in which terminal the user is currently logged on.
S0-+"x : %4, "2 )
Ex"2'(& : F who am I
C,22"-$ : (ate
P3#',1& : It is used to display the system date and time.
S0-+"x : $"+&
Ex"2'(& : F date
C,22"-$ : al
P3#',1& : It prints the calender for the specified year and month.
S0-+"x : *"( >2,-+4? >0&"#?
Ex"2'(& : F cal 96 1993
C,22"-$ : Id
P3#',1& : It is used to display the login name.
S0-+"x : )$
Ex"2'(& : F id
C,22"-$ : lear
P3#',1& : It is used to clear the screen.
S0-+"x : *(&"#
Ex"2'(& : F clear
C,22"-$ : Tput
P3#',1& : It is used to manipulate the screen.
S0-+"x : +'3+ > "++#)73+&1 ?
Ex"2'(& : F tput rmso
C,22"-$ : "name
P3#',1& : It is used to display the details about the OS in which we are wor%ing.
S0-+"x : 3-"2& @,'+),-1A
Ex"2'(& : F uname Gn
C,22"-$ : Tty
P3#',1& : It is used to %now the terminal name on which we wor%.
S0-+"x : ++0
Ex"2'(& : F tty
C,22"-$ : !wd
P3#',1& : It is used to display the absolute pathname of current wor%ing directory.
S0-+"x : '%$
Ex"2'(& : F pwd
C,22"-$ : ;c
P3#',1& : It is used to perform simple mathematical calculations.
S0-+"x : 7* >,'&#"+),-?
Ex"2'(& : F bc 3H6 I Jd
C,22"-$ : <s
P3#',1& : It is used to display the files in the current wor%ing directory.
S0-+"x : (1 @,'+),-1A >"#/32&-+1?
Ex"2'(& : F ls Gp
C,22"-$ : &cho
P3#',1& : It echoes the argument on the standard output device.
S0-+"x : &*4, @,'+),-1A >1+#)-/?
Ex"2'(& : F echo @;OO*,
C,22"-$ C *an
P3#',1& C It gives details about the uni- commands.
S0-+"x : 2"- > *,22"-$ -"2& ?
Ex"2'(& : F man echo
COMMAND GROUPING C FILTER COMMANDS
C,22"-$ : Head
P3#',1& : It is used to display the top portion of the file.
S0-+"x : 4&"$ @,'+),-1A >.)(& -"2&?
Ex"2'(& : F head -6 devi
C,22"-$ : Tail
P3#',1& : It is used to display the bottom portion of the file.
S0-+"x : +")( @,'+),-1A >.)(& -"2& ?
Ex"2'(& : F tail G6 devi
C,22"-$ : !r
P3#',1& : It is used to display the contents of the file by separating them into pages
and each page begins with the header information.
S0-+"x : '# @,'+),-1A >.)(& -"2& ?
Ex"2'(& : F pr devi
C,22"-$ : ut
P3#',1& : It is used to e-tract selected fields or columns from each line of one or
more files and display them on the standard output device.
S0-+"x : *3+ @,'+),-1A >.)(& -"2& ?
Ex"2'(& : F cut Gc6 devi
C,22"-$ : !aste
P3#',1& : It concatenates the line from each input file column by column with tab
characters in between them.
S0-+"x : '"1+& @,'+),-1A >.)(& -"2& ?
Ex"2'(& : F paste f0 f1
C,22"-$ : Doin
P3#',1& : It is used to e-tracts common lines from two sorted files and there should
be the common field in both file.
S0-+"x : D,)- @,'+),-1A >.)(& -"2&1 ? >.)(& -"2& 2?
Ex"2'(& : F .oin Ga0 f0 f1
C,22"-$ : "ni/
P3#',1& : It compares ad.acent lines in the file and displays the output by
eliminating duplicate ad.acent lines in it.
S0-+"x : 3-)E @,'+),-1A >.)(& -"2& ?
Ex"2'(& : F uni/ -c devi
C,22"-$ : Sort
P3#',1& : It sorts one or more files based on ASII se/uence and also to merge the
file.
S0-+"x : 1,#+ @,'+),-1A >.)(& -"2& ?
Ex"2'(& : F sort -r devi
C,22"-$ : >l
P3#',1& : It is used to add the line numbers to the file.
S0-+"x : -( @,'+),-1A @.)(&-"2&A
Ex"2'(& : F nl devi
C,22"-$ : Tr
P3#',1& : It is used to translate or delete a character or a string from the standard
input to produce the re/uired output.
S0-+"x : +# @,'+),-1A >1+#)-/1? >1+#)-/2?
Ex"2'(& : F tr Gt @a, @b, K deviL
C,22"-$ : Tee
P3#',1& : It is used to read the contents from standard input or from output of
another command and reproduces the output to boyh in standard output
and direct into output to one or more files.
S0-+"x : +&& @,'+),-1A >.)(& -"2& ?
Ex"2'(& : F tee date dat.t-t
C,22"-$ : grep
P3#',1& : It is used to search the specified pattern from one or more files.
S0-+"x : /#&' @,'+),-1A >'"++&#-? >.)(& -"2& ?
Ex"2'(& : F grep ManandN devi
Ex.NO:8 DIRECTORY COMMANDS AND PROCESS MANAGEMENT
COMMANDS
A)2
To Study about directory handling and !rocess *anagement ommands
C,22"-$ : m%dir
P3#',1& : It is used to create new directory or more than one directory.
S0-+"x : 26$)# >$)#&*+,#0 -"2& ?
Ex"2'(& : F m%dir riya
C,22"-$ : rmdir
P3#',1& : It is used to remove the directory if it is empty.
S0-+"x : #2$)# >$)#&*+,#0 -"2& ?
Ex"2'(& : F rmdir riya
C,22"-$ : cd
P3#',1& : It is used to change the control from one wor%ing directory to another
specified directory.
S0-+"x : *$ >$)#&*+,#0 -"2& ?
Ex"2'(& : F cd riya
C,22"-$ : cd ..
P3#',1& : It is used to /uit from current directory and move to the previous
directory.
S0-+"x : *$ ..
Ex"2'(& : F cd ..
P#,*&11 C,22"-$1
C,22"-$ : echo FF
P3#',1& : It is used to display the process number of the current shell.
S0-+"x : &*4, FF
Ex"2'(& : F echo FF
C,22"-$ : ps
P3#',1& : It is used to display the attributes of a process.
S0-+"x : '1
Ex"2'(& : F ps
F ps Gf B (isplay the ancestry of a process )
F ps Gu B (isplay the activities of a user )
F ps Ga B <ists processes of all users but not the system processes )
C,22"-$ : :
P3#',1& : It is shell operator which is used to run a process in the bac%ground.
S0-+"x C KcommandL :
Ex"2'(& : F sort emp.t-t :
C,22"-$ : nohup
P3#',1& : It permits the e-ecution of the process even after the user has logged out.
S0-+"x : -,43' >*,22"-$?
Ex"2'(& : F nohup sort emp.t-t B result is available on nohup.out )
C,22"-$ : %ill
P3#',1& : It is used to terminate the process.
S0-+"x : 6)(( >PID?
Ex"2'(& : F %ill 096
C,22"-$ : %ill FO
P3#',1& : FO is the system variable which stores the process id of the last bac%ground
.ob. The command %ill FO is used to %ill the last process.
S0-+"x : 6)(( FG
Ex"2'(& : F %ill FO
C,22"-$ : at
P3#',1& : It is used to e-ecute the process at the time specified.
S0-+"x : &*4, >+)2&?
Ex"2'(& : F at 05C9I Bor) F at 3 !* Bor) F at 5 C69 A*
Ex.NO:9 STUDY OF VI EDITOR C S!ELL PROGRAMMING
An editor is program that allows to see a portion of a file on the screen and to modify
characters and lines by simply typing at the cursor position. There are number of editors that
may be included with the "ni- system# including ed# e-# vi and &*AS.
T4& 5) E$)+,#
V) - vi stands for visual.
Pi is a full screen editor and is widely ac%nowledged as one of the most powerful editors
available .It is a full screen editor that allows the user to view and edit the entire document at
the same time.
The vi editor was written in the "niversity of alifornia at ;er%eley by ;ill Doy# who
is one of the co-founder of Sun *icrosystems.
F&"+3#&1 ,. 5) E$)+,#
1. It is very easy to learn and has more powerful and e-citing features.
2. It wor%s in great speed.
8. vi is case sensitive.
4. vi has powerful undo features than most other word processors#but it has no
formatting features.
M,$&1 ,. 5) E$)+,#
Pi editor wor%s in three modes of operations specified belowC
C,22"-$ M,$&: In this mode# all the %eys pressed by the user are interpreted to be editor
commands. >o te-t is displayed on the screen# even if corresponding %ey is pressed on
%eyboard.
I-1&#+ M,$&: This mode permits to insert new te-t# editing and replacement of e-isting te-t.
Once vi editor is in the insert mode# letters typed in the %eyboard are echoed on the screen.
T4& &x ,# &1*"'& *,(,- H : I M,$&: This mode allow us to give commands at the command
line.The bottom line of the vi editor is called the command line.vi uses the command line to
display messages and commands.
S+"#+)-/ %)+4 V) &$)+,#
S0-+"x: vi filename
M,5)-/ +4& *3#1,#
The cursor movement commands areC
C,22"-$ A*+),-
H or bac%space <eft one character
l or spacebar )ight one character
$ or - "p one line
D or H (own one line
I *oves forward a word
Qb *oves bac% a word
Qe *oves to the last character in the word
2RcharacterS *oves right to the specified character in a line
TRcharacterS *oves right and places it one character before the specified
character
9 or J *oves to the beginning of the file
QF *oves to the end of the file
< *oves to the last line of the file
+ *oves to the specified line number
E$)+)-/ +4& .)(&
Open the file using F vi filename
To add te-t at the end of the file# position the cursor at the last character of the file.
Switch from command mode to te-t input mode by pressing @a,.
Here @a, stands for append.
Inserting te-t in the middle of the file is possible by pressing @i,. The editor accepts
and inserts the typed character until &sc %ey is pressed.
C,22"-$ P3#',1&
I Inserts te-t to the left of the cursor
I Inserts te-t at the beginning of the line
A Append te-t to the right of the cursor
A Appends te-t at the end of the line
O Appends a new line below
O Appends a line above
D&(&+)-/ T&x+
2or deleting a character# move the cursor to the character # press @-,. The character
will disappear.
C,22"-$ P3#',1&
? (eletes one character
>- (eletes n number of characters
Q- (eletes on character at the cursor position
Q? (eletes on the character before the cursor position
(F or d (eletes a line from the cursor position to the end of the line
(9 (eletes from the cursor position to the starting of the line
Qdd (eletes the current line where the cursor is positioned
Qdw (eletes the word from the cursor position to the end of the word
T4& 3-$, .&"+3#&1
u-undo the recent changes
"- undo all changes in the current line
S"5)-/ +&x+
Cw G save the file and remains in edit mode
Cw/ G save the file and /uits from edit mode
C/ G /uit without changes from edit mode
J3)++)-/ 5)
!ress EE or @Cw/, in command mode.
S!ELL PROGRAMMING
The format for the various conditional statements and looping statements and the
relational operators used for those conditions are given below.
). *,-$)+),-
if condition
then
e-ecute commands
fi
). = &(1& *,-$)+),-
if condition
then
e-ecute commands
else
e-ecute commands
fi
). = &(). *,-$)+),- = 23(+) %"0 7#"-*4)-/
if condition
then
e-ecute commands
elif condition
then
e-ecute commands
else
e-ecute commands
fi
R&("+),-"( O'&#"+,#1
Operator Meaning
-e/ &/ual to
-ne >ot e/ual to
-gt +reater than
-ge +reater than or e/ual to
-lt <ess than
-le <ess than or e/ual to
C"1& *,-$)+),-
*ase e-pression in
pattern0) e-ecute commands ==
pattern1) e-ecute commands ==
pattern3) e-ecute commands ==
TTTTT..
esac
%4)(& (,,')-/
'hile e-pression
(o
e-ecute commands
done
3-+)( : %4)(&K1 *,2'(&2&-+
until R condition S
.,# (,,')-/
for variable in list
do
e-ecute commands
done
Ex.N,. 5 SIMPLE S!ELL PROGRAMS
Ex.N,. 5" G&++)-/ "-$ $)1'("0)-/ +4& "*"$&2)* "-$ '&#1,-"( $&+")(1
A)2
To get the input and display the academic# personal details.
A(/,#)+42
0. +et name# age# and address from the user.
1. !rint that message as similar.
3. +et mar%0# mar%1# and mar%3 from the user.
5. !rint that message as similar.
P#,/#"2
#display.sh
echo $n %&nter the name'
read s
echo $n %&nter the age'
read a
echo $n %&nter the address'
read adr
echo $n %(he name is )s'
echo $n %(he age is )a'
echo $n %(he address is )adr'
echo $n %&nter the mar*1'
read m1
echo $n %&nter the mar*+'
read m+
echo $n %&nter the mar*,'
read m,
echo $n %(he mar*1 is )m1'
echo $n %(he mar*+ is )m+'
echo $n %(he mar*, is )m,'
Sample Input & Output
) &nter the name -ohn
&nter the age 1.
&nter the address mad/rai
(he name is -ohn
(he age is 1.
(he address is mad/rai
&nter the mar*1 01
&nter the mar*+ 01
&nter the mar*, 21
(he mar*1 is 01
(he mar*+ is 01
(he mar*, is 21
Ex N,. 57 A#)+42&+)* O'&#"+),-1
A)2
To perform all arithmetic operations
A(/,#)+42
0. )ead two numbers from the user.
1. Add both the numbers.
3. !rint the summation of two numbers.
5. Subtract the second number from the first number
6. !rint the result.
8. *ultiply the two numbers
A. !rint the result.
I. (ivide the first number by second number.
P#,/#"2
echo enter the n/mbers
read n1 n+
n,34e5pr )n1 6 )n+4
n734e5pr )n1 8 )n+4
n934e5pr )n1 :; )n+4
n<34e5pr )n1 = )n+4
echo s/mmation o> )n1 and )n+ is )n,
echo di>>erence o> )n1 and )n+ is )n7
echo m/ltiplication o> )n1 and )n+ is )n9
echo di?ision o> )n1 by )n+ is )n<
Sample Input & Output
) enter the n/mbers
11 9
s/mmation o> 11 and 9 is 19
di>>erence o> 11 and 9 is 9
m/ltiplication o> 11 and 9 is 91
di?ision o> 11 by 9 is +
Ex. N, .6 PROGRAMS USING CONDITIONAL STATEMENTS
Ex. N, .6" O$$ H,#I E5&-
A)2
To chec% whether the given number is odd or even.
A(/,#)+42
0. +et a number from the user.
1. (ivide the number by 1.
3. hec% the remainder of the division.
5. If it is Eero then the given number is even.
6. Otherwise the given number is odd.
P#,/#"2
echo Gn Menter the numberN
read num
- U Ve-pr Fnum W 1V
if R F- Ge/ 9 S
then
echo MF- is an even numberN
else
echo MF- is a odd numberN
fi
S"2'(& I-'3+ C O3+'3+
F enter the numberC 00
00 is a odd number
F enter the numberC 69
69 is an even number
Ex. N,. 67 P,1)+)5& ,# N&/"+)5&
A)2
To chec% whether the given number is Hve or Gve or Eero.
A(/,#)+42
0. +et a number from the user.
1. hec% the number is greater than or less than Eero or e/ual to Eero.
3. If it is greater than Eero then the given number is Hve.
5. If it is less than Eero then the given number is Gve. Otherwise the given number is
Eero.
P#,/#"2
echo Gn Menter the numberN
read num
if R Fnum Ggt 9 S
then
echo MFnum is a positive numberN
elif R Fnum Glt 9 S
then
echo MFnum is a negative numberN
else
echo MFnum is EeroN
fi
S"2'(& I-'3+ C O3+'3+
F enter the numberC 00
00 is a positive number
F enter the numberC -6
69 is a negative number
F enter the numberC 9
9 is Eero
Ex. N,: 6* B)//&1+ "2,-/ +4#&& -327&#1
A)2
To find a biggest number among three numbers.
A(/,#)+42
0. +et three numbers from the user.
+# If the 0
st
number is greater than other two numbers then the 0
st
number is a biggest
numbers.
,# Otherwise if the 1
nd
number is greater than 3
rd
number then the 1
nd
number is a
biggest number.
7# Otherwise 3
rd
number is a biggest number.
P#,/#"2
echo -n X&nter the numbersX
read num0 num1 num3
if R Fnum0 -gt Fnum1 S :: R Fnum0 -gt Fnum3 S
then
echo XFnum0 is a biggest numberX
elif R Fnum1 -gt Fnum3 S
then
echo XFnum1 is a biggest numberX
else
echo XFnum3 is a biggest numberX
fi
S"2'(& I-'3+ C O3+'3+
F &nter the numbers 01 56 35
56 is a biggest number
Ex N,.6$ A#)+42&+)* O'&#"+),-1 - 1%)+*4 *"1&
A)2
To perform all the arithmetic operations using case statements.
A(/,#)+42
0. +et two numbers from the user.
1. Select the options .
3. &-ecute arithmetic operations using case statements..
5.!rint the output
P#,/#"2
echo M&nter two numbersN
read a b
echo MmenuN
echo M0.addN
echo M1.subN
echo M3.mulN
echo M 5. divN
echo M&nter your optionN
read option
case Foption in
0)cUVe-pr Fa H FbV==
1)cUVe-pr Fa - FbV==
cUVe-pr Fa YZ FbV==
cUVe-pr Fa 4 FbV==
esac
echo Fc
S"2'(& )-'3+ C ,3+'3+
&nter two numbers
5 6
menu
0.add
1.sub
3.mul
5.div
&nter your option
0
7
Ex N,.6& F)-$)-/ +4& "#&" ,. *)#*(&, 1E3"#&, #&*+"-/(& "-$ +#)"-/(&
A)2
To find the area of circle# s/uare# rectangle and triangle using case statements.
A(/,#)+42
0. +et two numbers from the user.
1. Select the option.
3. &-ecute the statement to find the area using case statements..
5. !rint the output
P#,/#"2
echo 0.circle
echo 1. rectangle
echo 3.s/uare
echo 5.triangle
echo enter your choice
read opt
case Fopt in
0) echo enter the radius
read r
areaUVe-pr Fr YZ Fr YZ 11 4 AV
echo Farea==
1) echo enter the length and breadth
read l b
areaUVe-pr Fl YZ FbV
echo Farea==
3) echo enter the side
read s
areaUVe-pr Fs YZ FsV
echo Farea==
5)echo enter the height and breadth
read b h
areaUVe-pr Fb YZ Fh YZ 0 4 1V
echo Farea==
Z) echo wrong choice==
esac
S"2'(& )-'3+ C ,3+'3+
0.circle
1. rectangle
3.s/uare
5.triangle
enter your choice
3
enter the side
6
16
Ex. N,. : TESTING AND LOOPS
Ex. N,.:" F)7,-"**) S&#)&1
A)2
To generate a fibonacci series of first n numbers
A(/,#)+42
0. +et the value n from the user.
1. Initial numbers of fibonacci series is 9#0.
3. "sing the sum of last ad.acent two numbers generate a ne-t number in the series.
5. )epeat the step 3 until n numbers are generated.
P#,/#"2
echo -n Xenter the limitX
read n
echo Xthe fibonacci series is C X
bU9
cU0
iU9
if R Fn -ge 1 S
then
echo -n X Fb FcX
nUVe-pr Fn - 1V
while R Fi -lt Fn S
do
aUVe-pr Fb H FcV
bUFc
cUFa
echo -n X FcX
iUVe-pr Fi H 0V
done
fi
S"2'(& I-'3+ C O3+'3+
F &nter the limit 6
The fibonacci series is
9 0 0 1 3
Ex. N,.:7 A#21+#,-/ N327&#
A)2
To hec% 'hether the given number is Armstrong or not.
A(/,#)+42
0. +et the number from the user.
1. &-tract each and every digit of the given number.
3. 2ind the cube of every digit and calculate the sum of all cubes.
5. hec% whether the sum is e/ual to the given number# if it is e/ual# the given
number is Armstrong number otherwise not.
P#,/#"2
echo -n Xenter the numberX
read num
-UFnum
sumU9
while R Fnum -gt 9 S
do
yUVe-pr Fnum W 09V
EUVe-pr Fy YZ Fy YZ FyV
sumUVe-pr Fsum H FEV
numUVe-pr Fnum 4 09V
done
if R F- -e/ Fsum S
then
echo F- is an Armstrong number
else
echo F- is not an Armstrong number
fi
S"2'(& I-'3+ C O3+'3+
F enter the numberC 3A0
3A0 is an armstrong number
F enter the numberC 699
699 is not an armstrong number
Ex. N,. :* S32 ,. - &5&- -327&#1
A)2
To write a shell program to find the sum of even numbers
A(/,#)+42
0. Start the program
1. )ead the number
3. InitialiEe iU1
5. alculate sumUsumH0
6. !rint the sum
8. Stop the program e-ecution
P#,/#"2
echo Menter the number of upper limitN
read n
IU1
U9
while R FI Glt Fn S
do
echo Mnumber is FIN
IUVe-pr FI H 1,
UVe-pr FI H F,
done
echo M the sum is FcN
S"2'(& I-'3+ C O3+'3+

&nter the number of upper limit 8
1
5
the sum is 8
Ex. N,: :$ C,27)-"+),-1 ,. 1 2 8
A)2
To generate all combinations of 0 1 3 using for loop
A(/,#)+42
0. Assign values 0 1 3 to first for loop
1. 2orm another for loop within the first for loop and assign values 0 1 3
3. 'ithin the second for loop e-ecute another for loop with values 0 1 3
5. lose all for loops
6. (isplay the outputs
P#,/#"2
for I in 0 1 3
do
for . in 0 1 3
do
for % in 0 1 3
do
&cho FI F. F%
done
done
done
S"2'(& ,3+'3+
000 001 003 010 011 013 030 031 033 100 101 103 110 111 113 300 301 303 310 311 313
330 331 333
Ex. N,: :& -
+4
',%&# ,. " /)5&- -327&#
A)2
To compute the n
th
power of a given number
A(/,#)+42
0. +et the value for the power : number to be computed.
1. InitialiEe the value for I as 1.
3. Set the variable ans as a.
5. )epeat the steps 6#8 until the value of I ie less than or e/ual to the power value.
6. *ultiply the value of ans and a.
8. Increment the I value.
A. (isplay the value ans as result
P#,/#"2
echo enter the number and its power
read a pow
iU1
ansUFa
while R Fi -le Fpow S
do
ansUVe-pr Fans YZ FaV
iUVe-pr Fi H 0V
done
echo Fans
S"2'(& ,3+'3+
F enter the number and its power
1 5
08
Ex. N, ;. COMMAND LINE SUBSTITUTION
Ex. N,: ;" P"()-$#,2& *4&*6)-/
A)2
To chec% whether the given string is palindrome or not using ommand line
substitution.
A(/,#)+42
0. +et the filename and string in a command line.
1. )everse the original string.
3. If the original string is e/ual to the reversed string then display a given string is
palindrome.
5. Otherwise display a given string is not palindrome.
P#,/#"2
QincludeKstdio.hL
QincludeKstring.hL
void mainBint argc# char ZargvRS)
[
char strR09S#revstrR09S=
int i#len#.U9=
ifBargc OU3)
[
printfBXYn !arameters missingX)=
e-itB9)=
\
strcpyBstr#argvR1S)=
lenUstrlenBargvR1S)=
forBiUlen=iLU 9=i--)
[
revstrR.SUstrRi-0S=
.HH=
\
ifBstrcmpBrevstr#str)UU9)
printfBXYn!alindromeYnX)=
else
printfBXYn>ot palindromeYnX)=
\
S"2'(& I-'3+ C O3+'3+
F a.out paly.c madam
!alindrome
F a.out paly.c sit
>ot palindrome

Ex. N,:;7 C,-*"+&-"+),- ,. +%, S+#)-/1
A)2
To concatenate given two strings using ommand line substitution.
A(/,#)+42
0. +et the two strings in command line.
1. opy the two arguments in two variables from the command line.
3. oncatenate the two strings using the built G in concatenate function.
5. (isplay the resultant string.
P#,/#"2
Linclude Kstdio.hL
Qinclude Kstring.hL
mainBint argc# char ZargvRS)
[
char str0R09S#str1R19S#str3R09S=
strcpyBstr0#argvR0S)=
strcpyBstr1#argvR1S)=
printfBXWsX#strcatBstr0#str1))=
\
S"2'(& I-'3+ C O3+'3+
F a.out concat.c )*$ &T
)*$&T
C PROGRAMMING ON UNI
Ex.-,.< BIGGEST AMONG MNK NUMBERS USING FUNCTIONS
AIM:
To write a program to find biggest among list of numbers.
ALGORIT!M:
0. +et the value of n as input.
1. +et the list of numbers in an array of siEe n.
3. Set the initial value as a biggest value.
5. Set the value of I is 0.
6. ompare it with other elements in an array.
8. If the biggest element is less than array element then interchange both the values.
A. )epeat steps 5 : 6 until I reaches n-0.
I. (isplay the biggest value.
PROGRAM:
QincludeKstdio.hL
QincludeKconio.hL
4Z 2unction (eclaration Z4
float largestBfloat aRS#int n)=
void mainB)
[
int n=
float valueR09S=
clrscrB)=
printfBXenter the value of nYnX)=
scanfBXWdX#:n)=
forBiU9=iKn=iHH)
[
scanfBXWfX#:valueRiS)=
\
printfBXThe <argest number among set of numbers isYnX)=
printfBXWfX#largestBvalue#n))=
getchB)=
\
float largestBfloat aRS#int n)
[
int i=
float ma-=
ma-UaR9S=
forBiU0=iKn=iHH)
[
ifBma-KaRiS)
[
ma-U aRiS=
\
\
returnBma-)=
\
SAMPLE INPUT :
enter the value of n
6
19 59 3I 17 0A
OUTPUT:
The <argest number among set of numbers is 59
Ex.N,.10 SNAPPING OF TNO NUMBERS USING POINTERS
AIM:
To write a program to swap two numbers using pointers.
ALGORIT!M:
0. (eclare the two pointer variables.
1. +et the value for both the variables.
3. Swap the values.
5. !rint the result.
PROGRAM:
QincludeKstdio.hL
QincludeKconio.hL
void swapBint Z#int Z)=
void swap0Bint#int)=
void mainB)
[
int a#b#c#d=
clrscrB)=
printfBX&nter the values of a and bCU X)=
scanfBXWd WdX#:a#:b)=
printfBX&nter the values of c and dCU X)=
scanfBXWd WdX#:c#:d)=
printfBXYn ;&2O)& S'A!!I>+ C X)=
printfBXYn The value of a and b is C WdYt Wd X#a#b)=
printfBXYn The value of c and d is C WdYt Wd X#c#d)=
printfBXYn A2T&) S'A!!I>+ C X)=
swapBa#b)=
swap0B:c#:d)=
printfBXYn *ethod isC-all by PalueX)=
printfBXYn ZZZZZZZZZZZZZZZZZZZZZZZZZZX)=
printfBXYn The value of a and b is C WdYt WdX#a#b)=
printfBXYn *ethod isC-all by Address or )eferenceX)=
printfBXYn ZZZZZZZZZZZZZZZZZZZZZZZZZZZX)=
printfBXYn The value of c and d is C WdYt WdX#c#d)=
getchB)=
\
void swapBint Zc#int Zd)
[
int t=
tUZc=
ZcUZd=
ZdUt=
\
void swap0Bint a#int b)
[
int t=
tUa=
aUb=
bUa=
\
SAMPLE INPUT:
&nter the values of a and bC U 1 5
&nter the values of c and dC U 8 6
OUTPUT:
;&2O)& S'A!!I>+C
The value of a and b isC 1 5
The value of c and d isC 8 6
AFTER SNAPPING:
*ethod isC-all by Palue
The value of a and b isC 1 5
*ethod isC-all by Address or )eference
The value of c and d isC 6 8
Ex.N,.11 FILE MANAGEMENT
AIM:
To !erform the cat command operations B reate# (isplay and "pdate ) in uni- by
using program using 2ile concept.
ALGORIT!M:
0. )ead a choice to perform create or display or update operation.
1. If it is reate# then create a new file with its contents.
3. If it is display# then display the contents from a file which is created later.
5. If it is update# then append the new contents to an e-isting file.
PROGRAM:
QincludeKstdio.hL
void mainB)
[
2I<& Zfptr=
char ch#fnR19S=
int op=
do
[
printfBX 2I<& *A>A+&*&>T O!&)ATIO>S YnX)=
printfBX 0. reate YnX)=
printfBX 1. (isplay YnX)=
printfBX 3. "pdate YnYnX)=
printfBX &nter the choice CX)=
scanfBXWdX#:op)=
switchBop)
[
case 0C
printfBX&nter the file name to be createYnX)=
scanfBXWsX#fn)=
fptrUfopenBfn#XwX)=
printfBX&nter the data to be stored in the fileYnX)=
scanfBXWcX#:ch)=
whileBchOU]F])
[
fprintfBfptr#XWcX#ch)=
scanfBXWcX#:ch)=
\
fcloseBfptr)=
brea%=
case 1C
fptrUfopenBfn#XrX)=
whileBOfeofBfptr))
[
chUgetcBfptr)=
ifBchUU]Yt])
printfBXYtX)=
else ifBchUU]Yn])
printfBXYnX)=
else
printfBXWcX#ch)=
\
fcloseBfptr)=
brea%=
case 3C
fptrUfopenBfn#XaX)=
printfBX&nter the updated data to be stored in the fileYnX)=
scanfBXWcX#:ch)=
whileBchOU]F])
[
fprintfBfptr#XWcX#ch)=
scanfBXWcX#:ch)=
\
fcloseBfptr)=
brea%=
defaultC
printfBXIllegal numberYnX)=
brea%=
\
\
whileBopLU0 :: opKU3)=
\
SAMPLE INPUT AND OUTPUT:
F ** *"+.*
F ".,3+
2I<& *A>A+&*&>T O!&)ATIO>S YnX)=
0. reate
1. (isplay
3. "pdate
&nter the choiceC 0
&nter the file name to be create input.t-t
&nter the data to be stored in the file
N&(*,2& +, RMKCET
2I<& *A>A+&*&>T O!&)ATIO>S YnX)=
0. reate
1. (isplay
3. "pdate
&nter the choiceC 1
N&(*,2& +, RMKCET
2I<& *A>A+&*&>T O!&)ATIO>S YnX)=
0. reate
1. (isplay
3. "pdate
&nter the choiceC 3
&nter the updated data to be stored in the file
RMKCET 4"1 ; D&'"#+2&-+1
2I<& *A>A+&*&>T O!&)ATIO>S YnX)=
0. reate
1. (isplay
3. "pdate
&nter the choiceC 1
N&(*,2& +, RMKCET
RMKCET 4"1 ; D&'"#+2&-+1
2I<& *A>A+&*&>T O!&)ATIO>S YnX)=
0. reate
1. (isplay
3. "pdate
&nter the choiceC 5
I((&/"( -327&#
Ex.N,.12 DYNAMIC MEMORY ALLOCATION
AIM:
To write a program to Search a String using (ynamic *emory Allocation oncept.
ALGORIT!M:
1# (eclare an array of pointer variables one containing strings and the other containing
the string to be searched.
1. +et the value for both the variables.
,# ompare the string to be searched in the array of strings.
7# If found !rint the result.
PROGRAM:
QincludeKstring.hL
QincludeKstdio.hL
mainB )
[
char ZtUBcharZ)mallocB09)=
char ZsR6SU[ M!ASA<N#NO;O<N#N;ASIN#N<IS!N#N2O)T)A>N\=
printfBM&nter the String to be SearchedYnN)=
scanfBMWsN#:t)=
search7s#t#6)=
\
searchBchar ZsR6S#char Zt#int n)=
[
int i=
forBiU9=iKn=iHH)
[
ifBOstrcmpBZsHi)#t))
[
printfBNString Ws is successfully searched YnN#t)=
brea%=
\
else ifBiUUn-0)
printfBM>ot found YnN)=
\\
SAMPLE INPUT C OUTPUT

&nter the String to be searched
!ASA<
String !ASA< is successfully searched

You might also like