ge2155 lab manual

Upload: gokul-prabu

Post on 03-Jun-2018

220 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/11/2019 GE2155 Lab Manual

    1/45

    GE2155 COMPUTER PRACTICE

    LABORATORY-II

    LAB MANUAL

    ,

    ASSISTANT PROFESSOR,

    DEPARTMENT OF CSE,

    R.M.K.C.E.T, PUDUVOYAL-601 206.

    1

  • 8/11/2019 GE2155 Lab Manual

    2/45

    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'"+)/ S+&: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

    Operating

    Hardware

  • 8/11/2019 GE2155 Lab Manual

    3/45

    F3*+) " O'"+)/ S+&

    C"$ )+'#&+"+): 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+"*&: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 ""/&&+:The OS handles the etremely important ob of allocating

    memory for various processes running on the system.

    P#*& ""/&&+: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)*& " 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 I? was rewritten in @, language in 073.Today# ">I? is a giant Os and is much

    powerful than most of its counter parts.

  • 8/11/2019 GE2155 Lab Manual

    4/45

    ">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 eecuting 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 eecuting

    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 allocatesresources including use of the !" and mediates accesses to the hardware.

    Application portability is the ability of a single application to be eecuted on various

    types of computer hardware without being modified. This is one of the important advantages

    of ">I?.

    FEATURES OF UNI:

    1. M3(+)+")/

    Other Applications

    Standard Application

    Standard Libraries

    File System Processcontrol

    Hardware

    fopen

    ()for% B )

    U!"

  • 8/11/2019 GE2155 Lab Manual

    5/45

    *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(+)3 C"'"7)()+

    *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#)+

    "ni allows sharing of data. &very user must have a

  • 8/11/2019 GE2155 Lab Manual

    6/45

    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

    eecuting. It also handles the information echange between the terminals such as tape drives

    and printers etc.#

    F3*+) 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.

  • 8/11/2019 GE2155 Lab Manual

    7/45

    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) B3#& 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# 4&((: It is developed by (avid +.$orn. This is superset of ;ourne shellan

    it has more capabilities.

    (iii) C S4&((: It is developed by ;il Doy. It is similar to !rogramming language.

    F&"+3#& 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 eecuted using a single command.

    S+"#+)/ " UNI &) = 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 &) =L//)/ O3+

  • 8/11/2019 GE2155 Lab Manual

    8/45

    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 eit at the dollar prompt. Then the systems display the loginC

    !rompt on the screen#

    Ex.NO:2 BASIC UNI COMMANDS

    A)

    To Study about basic "ni ommands.

    FILE MANIPULATION COMMANDS

    C"$ :at

    P3#'& : It is used to display the contents of the file as well as used to create a new

    file.

    S+"x :*"+ >)(& "& ?

    Ex"'(& : F cat devi

    C"$ :*ore

    P3#'& :It is used to display the contents of the file on the screen at a time.

    S+"x :#& >)(& "& ?

    Ex"'(& : F more devi

    C"$ :'c

  • 8/11/2019 GE2155 Lab Manual

    9/45

    P3#'& :It is used to count the number of lines #words and characters in a file or

    group of files.

    S+"x :%* @'+) >)(& "& ?

    Ex"'(& : F wc Gl devi

    C"$ :2ile

    P3#'& :It is used to determine the type of the file.

    S+"x :)(& >)(& "& ?

    Ex"'(& : F file devi

    C"$ :Spell

    P3#'& :It is used to find the spelling errors in the file.

    S+"x :'&(( @'+) >)(& "& ?

    Ex"'(& : F spell -b devi

    C"$ :Split

    P3#'& :It is used to split the given file into smaller pieces of given siEe.

    S+"x C '()+ =)& >)(& "& ? > '()++&$ )(& "& ?

    Ex"'(& : F split G1 devi de

    C"$ :p

    P3#'& :It is used to copy one or more files.

    S+"x :*"+ >3#*& )(& "& ? >$&+)"+) )(& "&?

    Ex"'(& : F cp devi latha

    C"$ :*v

    P3#'& :It is used to move a file within a directory with different names and also

  • 8/11/2019 GE2155 Lab Manual

    10/45

    used to move a file to different directory with its original name.

    S+"x : >3#*& )(& "& ? >$&+)"+) )(& "&?

    Ex"'(& : F mv devi eya

    C"$ :m

    P3#'& :It is used to remove a file from the dis%.

    S+"x :# >)(& "& ?

    Ex"'(& : F rm devi

    GENERAL PURPOSE COMMANDS

    C"$ : ;anner

    P3#'& :It is used to display its argument in large letters.

    S+"x :7" > +#)/ ?

    Ex"'(& :F banner ;OO*

    C"$ : 'ho

    P3#'& :It is used to get the information about all the users currently wor%ing in

    the system.

    S+"x :%4

    Ex"'(& : F who

    C"$ : 'ho am i

    P3#'& :It is used to %now in which terminal the user is currently logged on.

    S+"x :%4 " )

    Ex"'(& : F who am I

  • 8/11/2019 GE2155 Lab Manual

    11/45

    C"$ : (ate

    P3#'& :It is used to display the system date and time.

    S+"x :$"+&

    Ex"'(& : F date

    C"$ : al

    P3#'& :It prints the calender for the specified year and month.

    S+"x : *"( >+4? >&"#?

    Ex"'(& : F cal 96 1993

    C"$ : Id

    P3#'& :It is used to display the login name.

    S+"x :)$

    Ex"'(& : F id

    C"$ : lear

    P3#'& :It is used to clear the screen.

    S+"x :*(&"#

    Ex"'(& : F clear

    C"$ : Tput

    P3#'& :It is used to manipulate the screen.

    S+"x : +'3+ > "++#)73+& ?

    Ex"'(& : F tput rmso

    C"$ : "name

  • 8/11/2019 GE2155 Lab Manual

    12/45

    P3#'& :It is used to display the details about the OS in which we are wor%ing.

    S+"x :3"& @'+)

    Ex"'(& : F uname Gn

    C"$ : Tty

    P3#'& :It is used to %now the terminal name on which we wor%.

    S+"x : ++

    Ex"'(& :F tty

    C"$ : !wd

    P3#'& :It is used to display the absolute pathname of current wor%ing directory.

    S+"x :'%$

    Ex"'(& :F pwd

    C"$ : ;c

    P3#'& :It is used to perform simple mathematical calculations.

    S+"x :7* >'"+)?

    Ex"'(& :F bc 36 Jd

    C"$ :"#/3&+?

    Ex"'(& :F ls Gp

    C"$ :&cho

    P3#'& :It echoes the argument on the standard output device.

    S+"x :&*4 @'+) >+#)/?

    Ex"'(& :F echo @;OO*,

  • 8/11/2019 GE2155 Lab Manual

    13/45

    C"$ C *an

    P3#'& C It gives details about the uni commands.

    S+"x : " > *"$ "& ?

    Ex"'(& :F man echo

    COMMAND GROUPING FILTER COMMANDS

    C"$ :Head

    P3#'& :It is used to display the top portion of the file.

    S+"x :4&"$ @'+) >)(& "&?

    Ex"'(& : F head -6 devi

    C"$ :Tail

    P3#'& :It is used to display the bottom portion of the file.

    S+"x :+")( @'+) >)(& "& ?

    Ex"'(& : F tail G6 devi

    C"$ :!r

    P3#'& :It is used to display the contents of the file by separating them into pages

    and each page begins with the header information.

    S+"x :'# @'+) >)(& "& ?

    Ex"'(& : F pr devi

    C"$ :ut

    P3#'& :It is used to etract selected fields or columns from each line of one or

    more files and display them on the standard output device.

    S+"x :*3+ @'+) >)(& "& ?

    Ex"'(& : F cut Gc6 devi

  • 8/11/2019 GE2155 Lab Manual

    14/45

    C"$ :!aste

    P3#'& :It concatenates the line from each input file column by column with tab

    characters in between them.

    S+"x :'"+& @'+) >)(& "& ?

    Ex"'(& : F paste f0 f1

    C"$ :Doin

    P3#'& :It is used to etracts common lines from two sorted files and there should

    be the common field in both file.

    S+"x :) @'+) >)(& "&1 ? >)(& "& 2?

    Ex"'(& : F oin Ga0 f0 f1

    C"$ :"ni/

    P3#'& :It compares adacent lines in the file and displays the output by

    eliminating duplicate adacent lines in it.

    S+"x :3) @'+) >)(& "& ?

    Ex"'(& : F uni/ -c devi

    C"$ :Sort

    P3#'& :It sorts one or more files based on ASII se/uence and also to merge the

    file.

    S+"x :#+ @'+) >)(& "& ?

    Ex"'(& : F sort -r devi

    C"$ :>l

    P3#'& :It is used to add the line numbers to the file.

  • 8/11/2019 GE2155 Lab Manual

    15/45

    S+"x :( @'+) @)(&"&

    Ex"'(& : F nl devi

    C"$ :Tr

    P3#'& :It is used to translate or delete a character or a string from the standard

    input to produce the re/uired output.

    S+"x :+# @'+) >+#)/1? >+#)/2?

    Ex"'(& : F tr Gt @a, @b, K deviL

    C"$ :Tee

    P3#'& :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.

    S+"x :+&& @'+) >)(& "& ?

    Ex"'(& : F tee date dat.tt

    C"$ :grep

    P3#'& :It is used to search the specified pattern from one or more files.

    S+"x :/#&' @'+) >'"++? >)(& "& ?

    Ex"'(& : F grep ManandN devi

    Ex.NO:8 DIRECTORY COMMANDSAND PROCESS MANAGEMENT

  • 8/11/2019 GE2155 Lab Manual

    16/45

    COMMANDS

    A)

    To Study about directory handling and !rocess *anagement ommands

    C"$ :m%dir

    P3#'& :It is used to create new directory or more than one directory.

    S+"x :$)# >$)#&*+# "& ?

    Ex"'(& : F m%dir riya

    C"$ :rmdir

    P3#'& :It is used to remove the directory if it is empty.

    S+"x :#$)# >$)#&*+# "& ?

    Ex"'(& :F rmdir riya

    C"$ :cd

    P3#'& :It is used to change the control from one wor%ing directory to another

    specified directory.

    S+"x :*$ >$)#&*+# "& ?

    Ex"'(& : F cd riya

    C"$ :cd ..

    P3#'& :It is used to /uit from current directory and move to the previous

    directory.

    S+"x :*$ ..

    Ex"'(& : F cd ..

    P#*& C"$

    C"$ : echo FF

    P3#'& :It is used to display the process number of the current shell.

    S+"x :&*4

    Ex"'(& :F echo FF

  • 8/11/2019 GE2155 Lab Manual

    17/45

    C"$ :ps

    P3#'& :It is used to display the attributes of a process.

    S+"x :'

    Ex"'(& :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 *"$?

    Ex"'(& :F nohup sort emp.tt B result is available on nohup.out )

    C"$ : %ill

    P3#'& :It is used to terminate the process.

    S+"x :)(( >PID?

    Ex"'(& :F %ill 096

    C"$ : %ill F

    P3#'& :F is the system variable which stores the process id of the last bac%ground

    ob. The command %ill F is used to %ill the last process.

    S+"x :)((

    Ex"'(& :F %ill F

    C"$ : at

    P3#'& :It is used to eecute the process at the time specified.

  • 8/11/2019 GE2155 Lab Manual

    18/45

  • 8/11/2019 GE2155 Lab Manual

    19/45

    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$& ) E$)+#

    Pi editor wor%s in three modes of operations specified belowC

    C"$ M$&: In this mode# all the %eys pressed by the user are interpreted to be editor

    commands. >o tet is displayed on the screen# even if corresponding %ey is pressed on

    %eyboard.

    I+ M$&: This mode permits to insert new tet# editing and replacement of eisting tet.

    Once vi editor is in the insert mode# letters typed in the %eyboard are echoed on the screen.

    T4& &x # &*"'& *( H : 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) &$)+#

    S+"x:vi filename

    M)/ +4& *3##

    The cursor movement commands areC

    C"$ A*+)

    H or bac%space

  • 8/11/2019 GE2155 Lab Manual

    20/45

    TRcharacter *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 tet at the end of the file# position the cursor at the last character of the file.

    Switch from command mode to tet input mode by pressing @a,.

    Here @a, stands for append.

    Inserting tet 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"$ P3#'&

    I Inserts tet to the left of the cursor

    I Inserts tet at the beginning of the line

    A Append tet to the right of the cursor

    A Appends tet 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"$ P3#'&

    ? (eletes one character

    > (eletes n number of characters

    Q (eletes on character at the cursor position

  • 8/11/2019 GE2155 Lab Manual

    21/45

    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#&

    u-undo the recent changes

    "- undo all changes in the current line

    S")/ +&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)++)/ )

    !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 conditionthen

    eecute commandsfi

    ) = &(& *$)+)

    if conditionthen

    eecute commandselse

    eecute commandsfi

  • 8/11/2019 GE2155 Lab Manual

    22/45

    ) = &() *$)+) = 3(+) %" 7#"*4)/

    if conditionthen

    eecute commands

    elif conditiontheneecute commands

    elseeecute commands

    fi

    R&("+)"( O'"+#

    Operator Meaning

    -e/ &/ual to

    -ne >ot e/ual to

    -gt +reater than

    -ge +reater than or e/ual to

    -lt

  • 8/11/2019 GE2155 Lab Manual

    23/45

    done

    3+)( : %4)(& *'(&&+

    until R condition

    # (')/for variable in list

    do

    eecute commands

    done

    Ex.N. 5 SIMPLE S!ELL PROGRAMS

    Ex.N. 5" G&++)/ "$ $)'(")/ +4& "*"$&)* "$ '"( $&+")(

    A)

    To get the input and display the academic# personal details.

    A(/#)+4

    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#/#"

    #display.shecho $n %&nter the name'read secho $n %&nter the age'read aecho $n %&nter the address'read adrecho $n %he name is s'echo $n %he age is a'

    echo $n %he address is adr'echo $n %&nter the mar*1'read m1echo $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.

  • 8/11/2019 GE2155 Lab Manual

    24/45

    &nter the address mad/raihe name is -ohnhe age is 1.he address is mad/rai&nter the mar*1 0&nter the mar*+ 0&nter the mar*, 2

    he mar*1 is 0he mar*+ is 0he mar*, is 2

    Ex N. 57 A#)+4&+)* O'"+)

    A)

    To perform all arithmetic operations

    A(/#)+4

    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 number6. !rint the result.8. *ultiply the two numbers. !rint the result.. (ivide the first number by second number.

    P#/#"

    echo enter the n/mbersread n1 n+n,34e5pr n1 6 n+4n734e5pr n1 8 n+4n934e5pr n1 :; n+4

    n n1 and n+ is n,echo di>>erence o> n1 and n+ is n7echo m/ltiplication o> n1 and n+ is n9echo di?ision o> n1 by n+ is n 1 and 9 is 19di>>erence o> 1 and 9 is 9m/ltiplication o> 1 and 9 is 9di?ision o> 1 by 9 is +

  • 8/11/2019 GE2155 Lab Manual

    25/45

  • 8/11/2019 GE2155 Lab Manual

    26/45

    69 is an even number

    Ex. N. 67 P)+)& # N&/"+)&

    A)

    To chec% whether the given number is ve or Gve or Eero.

    A(/#)+4

    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 ve.5. If it is less than Eero then the given number is Gve. Otherwise the given number is

    Eero.P#/#"

    echo Gn Menter the numberN

    read num

    if R Fnum Ggt 9

    then

    echo MFnum is a positive numberN

    elif R Fnum Glt 9

    then

    echo MFnum is a negative numberN

    else

    echo MFnum is EeroN

    fi

  • 8/11/2019 GE2155 Lab Manual

    27/45

    S"'(& I'3+ 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)//&+ "/ +4#&& 37

    A)

    To find a biggest number among three numbers.

    A(/#)+4

    0. +et three numbers from the user.+# If the 0stnumber is greater than other two numbers then the 0stnumber is a biggest

    numbers.

    ,# Otherwise if the 1ndnumber is greater than 3rdnumber then the 1ndnumber is abiggest number.

    7# Otherwise 3rdnumber is a biggest number.

    P#/#"

    echo -n X&nter the numbersXread num0 num1 num3if R Fnum0 -gt Fnum1 :: R Fnum0 -gt Fnum3 then echo XFnum0 is a biggest numberXelif R Fnum1 -gt Fnum3

  • 8/11/2019 GE2155 Lab Manual

    28/45

    then echo XFnum1 is a biggest numberXelse echo XFnum3 is a biggest numberXfi

    S"'(& I'3+ O3+'3+

    F &nter the numbers 01 56 3556 is a biggest number

    Ex N.6$ A#)+4&+)* O'"+) - %)+*4 *"&

    A)

    To perform all the arithmetic operations using case statements.

    A(/#)+4

    0. +et two numbers from the user.1. Select the options .3. &ecute arithmetic operations using case statements..

    5.!rint the output

    P#/#"

    echo M&nter two numbersNread a becho MmenuNecho M0.addNecho M1.subNecho M3.mulNecho M 5. divNecho M&nter your optionN

    read optioncase Foption in

  • 8/11/2019 GE2155 Lab Manual

    29/45

    0)cUVepr Fa FbV==1)cUVepr Fa - FbV==cUVepr Fa YZ FbV==cUVepr Fa 4 FbV==esac

    echo Fc

    S"'(& )'3+ 3+'3+

    &nter two numbers 5 6

    menu0.add1.sub3.mul5.div

    &nter your option07

    Ex N.6& F)$)/ +4& "#&" *)#*(&, 3"#&, #&*+"/(& "$ +#)"/(&

    A)

    To find the area of circle# s/uare# rectangle and triangle using case statements.

    A(/#)+4

    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#/#"

    echo 0.circleecho 1. rectangleecho 3.s/uareecho 5.triangleecho enter your choiceread opt

    case Fopt in0) echo enter the radius

  • 8/11/2019 GE2155 Lab Manual

    30/45

    read r areaUVepr Fr YZ Fr YZ 11 4 V echo Farea==

    1) echo enter the length and breadth read l b

    areaUVepr Fl YZ FbV echo Farea==

    3) echo enter the side read s areaUVepr Fs YZ FsV echo Farea==

    5)echo enter the height and breadth read b h areaUVepr Fb YZ Fh YZ 0 4 1V

    echo Farea==Z) echo wrong choice==

    esac

    S"'(& )'3+ 3+'3+

    0.circle1. rectangle3.s/uare5.triangleenter your choice

    3enter the side 616

    Ex. N. TESTING AND LOOPS

    Ex. N." F)7"**) S)&

    A)

    To generate a fibonacci series of first n numbers

    A(/#)+4

    0. +et the value n from the user.

    1. Initial numbers of fibonacci series is 9#0.

    3. "sing the sum of last adacent two numbers generate a net number in the series.

    5. epeat the step 3 until n numbers are generated.

    P#/#"

    echo -n Xenter the limitXread n

  • 8/11/2019 GE2155 Lab Manual

    31/45

    echo Xthe fibonacci series is C XbU9cU0iU9if R Fn -ge 1

    then echo -n X Fb FcX nUVepr Fn - 1V while R Fi -lt Fn do aUVepr Fb FcV bUFc cUFa echo -n X FcX iUVepr Fi 0V done

    fi

    S"'(& I'3+ O3+'3+

    F &nter the limit 6 The fibonacci series is9 0 0 1 3

    Ex. N.7 A#+#/ N37

    A)

    To hec% 'hether the given number is Armstrong or not.

    A(/#)+4

    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#/#"

    echo -n Xenter the numberX

    read numUFnum

  • 8/11/2019 GE2155 Lab Manual

    32/45

  • 8/11/2019 GE2155 Lab Manual

    33/45

    IU1U9while R FI Glt Fn doecho Mnumber is FIN

    IUVepr FI 1,UVepr FI F,doneecho M the sum is FcN

    S"'(& I'3+ O3+'3+

    &nter the number of upper limit 8 1

    5the sum is 8

    Ex. N: $ C7)"+) 1 2 8

    A)

    To generate all combinations of 0 1 3 using for loop

    A(/#)+4

    0. Assign values 0 1 3 to first for loop1.2orm another for loop within the first for loop and assign values 0 1 33. 'ithin the second for loop eecute another for loop with values 0 1 35. lose all for loops6. (isplay the outputs

    P#/#"

    for I in 0 1 3do

    for in 0 1 3do

  • 8/11/2019 GE2155 Lab Manual

    34/45

    for % in 0 1 3do

    &cho FI F F%done

    done

    done

    S"'(& 3+'3+

    000 001 003 010 011 013 030 031 033 100 101 103 110 111 113 300 301 303 310 311 313330 331 333

    Ex. N: & +4'% " /)& 37

    A)

    To compute the nthpower of a given number

    A(/#)+4

    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.. (isplay the value ans as result

    P#/#"

    echo enter the number and its powerread a pow

  • 8/11/2019 GE2155 Lab Manual

    35/45

    iU1ansUFawhile R Fi -le Fpow doansUVepr Fans YZ FaV

    iUVepr Fi 0Vdoneecho Fans

    S"'(& 3+'3+

    enter the number and its power1 508

    Ex. N ;. COMMAND LINE SUBSTITUTION

    Ex. N: ;" P"()$#& *4&*)/

    A)

    To chec% whether the given string is palindrome or not using ommand linesubstitution.

    A(/#)+4

    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#/#"

    QincludeKstdio.hLQincludeKstring.hL

  • 8/11/2019 GE2155 Lab Manual

    36/45

  • 8/11/2019 GE2155 Lab Manual

    37/45

    strcpyBstr1#argvR1)=printfBXWsX#strcatBstr0#str1))=\

    S"'(& I'3+ O3+'3+

    F a.out concat.c *$ &T *$&T

    C PROGRAMMING ON UNI

    Ex..< BIGGEST AMONG N 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.. epeat steps 5 : 6 until I reaches n-0.

    . (isplay the biggest value.

  • 8/11/2019 GE2155 Lab Manual

    38/45

  • 8/11/2019 GE2155 Lab Manual

    39/45

    Ex.N.10 SAPPING OF TO 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.hLQincludeKconio.hL

  • 8/11/2019 GE2155 Lab Manual

    40/45

    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>+CThe value of a and b isC 1 5The value of c and d isC 8 6

    AFTER SAPPING:*ethod isC-all by Palue

  • 8/11/2019 GE2155 Lab Manual

    41/45

    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 byusing 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 eisting file.

    PROGRAM:

  • 8/11/2019 GE2155 Lab Manual

    42/45

    QincludeKstdio.hLvoid mainB)[ 2IT 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 0CprintfBX&nter the file name to be createYnX)=scanfBXWsX#fn)=fptrUfopenBfn#XwX)=

    printfBX&nter the data to be stored in the fileYnX)=scanfBXWcX#:ch)=whileBchU]F])[fprintfBfptr#XWcX#ch)=scanfBXWcX#:ch)=\fcloseBfptr)=

    brea%= case 1C

    fptrUfopenBfn#XrX)=whileBfeofBfptr))[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)=whileBchU]F])

    [fprintfBfptr#XWcX#ch)=

  • 8/11/2019 GE2155 Lab Manual

    43/45

    scanfBXWcX#:ch)=\fcloseBfptr)=

    brea%= defaultC

    printfBXIllegal numberYnX)=brea%=

    \ \ whileBopLU0 :: opKU3)=\SAMPLE INPUT AND OUTPUT:

    ** *"+.*

    ".3+

    2IA+&*&>T O!&ATIO>S YnX)=

    0. reate1. (isplay3. "pdate

    &nter the choiceC 0&nter the file name to be create input.tt

    &nter the data to be stored in the file&(*& + RMKCET

    2IA+&*&>T O!&ATIO>S YnX)=0. reate1. (isplay3. "pdate

    &nter the choiceC 1&(*& + RMKCET

    2IA+&*&>T O!&ATIO>S YnX)=0. reate1. (isplay3. "pdate

    &nter the choiceC 3&nter the updated data to be stored in the fileRMKCET 4" ; D&'"#+&+

    2IA+&*&>T O!&ATIO>S YnX)=0. reate1. (isplay3. "pdate

    &nter the choiceC 1&(*& + RMKCET

    RMKCET 4" ; D&'"#+&+

    2IA+&*&>T O!&ATIO>S YnX)=0. reate1. (isplay

    3. "pdate&nter the choiceC 5

  • 8/11/2019 GE2155 Lab Manual

    44/45

  • 8/11/2019 GE2155 Lab Manual

    45/45

    PROGRAM:

    QincludeKstring.hLQincludeKstdio.hLmainB )

    [ char ZtUBcharZ)mallocB09)=

    char ZsR6U[ M!ASA