cp2 lab

75
2 2 BASIC UNIX COMMANDS

Upload: selvaragini-sekar

Post on 10-Nov-2014

26 views

Category:

Documents


3 download

TRANSCRIPT

22

BASIC UNIX COMMANDS

22

(A) WORKING WITH FILES

1.To create a file.

Syntax :cat >filename[cplab2@localhost ~]$ cat > departmentcseece

2.To display or view a file

Syntax: cat filename[cplab2@localhost ~]$ cat departmentcseeceit

3. To display file contents with line number.

Syntax:cat-n filename[cplab2@localhost ~]$ cat -n department1 cse2 it

4. To display non-printing characters.

Syntax:cat-v filename[cplab2@localhost ~]$ cat -v departmentcseit

5. To merge or concatenate two files into a new file.

Syntax:cat file1 >> file2 (Appends file2 at the end of file1)[cplab2@localhost ~]$ cat >csecc1cc2cc3[cplab2@localhost ~]$ cat department cse >college or cat department>>cse[cplab2@localhost ~]$ cat collegecseitcc1cc2cc3[cplab2@localhost ~]$

22

(B) WORKING WITH DIRECTORIES

1. To display current working directory

Syntax: pwd[cplab2@localhost ~]$ pwd/home/cplab2

2. To create a new directory

Syntax: mkdir [options] directory[cplab2@localhost ~]$ mkdir csea

3. To change the working directory

Syntax: cd directory[cplab2@localhost ~]$ cd csea[cplab2@localhost csea]$ cat > studentsAnil

4. To move just above one level we are in.

Syntax: cd ..[cplab2@localhost csea]$ cd ..[cplab2@localhost~]$

5. To remove directory.[directories are removed only when they are empty.]

Syntax: rmdir directory[cplab2@localhost ~]$ rmdir csearmdir: csea: Directory not empty[cplab2@localhost ~]$ cd cseaSyntax: rm [options] filename[cplab2@localhost csea]$ rm students (To remove a file) [cplab2@localhost csea]$ cd ..[cplab2@localhost ~]$ rmdir csea[cplab2@localhost ~]$ cd csea (After removing the directory)-bash: cd: csea: No such file or directory[cplab2@localhost ~]$ mkdir csea[cplab2@localhost ~]$ cd csea[cplab2@localhost csea]$ pwd/home/cplab2/csea

6. To clear the screen

[cplab2@localhost csea]$ tput clear

22

7. To copy the contents of one file to another file and from one place to another.

Syntax: cp [options]    old_filename    new_filename[cplab2@localhost ~]$ cat >college1CSEITMECH[cplab2@localhost ~]$ cat >college2BIOTECHME[cplab2@localhost ~]$ cat college1 college2>College[cplab2@localhost ~]$ cat CollegeCSEITMECHBIOTECHME[cplab2@localhost ~]$ cp College ATCE[cplab2@localhost ~]$ cat ATCECSEITMECHBIOTECHME[cplab2@localhost ~]$ cat >file11abcdef[cplab2@localhost ~]$ cat >file12fhigkd[cplab2@localhost ~]$ cp file11 file13[cplab2@localhost ~]$ cat file13abcdef[cplab2@localhost ~]$ cp file14 file15cp: cannot stat `file14': No such file or directory[cplab2@localhost ~]$ cp file13 file12[cplab2@localhost ~]$ cat file12

22

(C) PLAYING WITH FILES

1.To copy files from or to the different directories.

[cplab2@localhost ~]$ cp /home/cplab2/csea/file2 /home/cplab2/csec/file2[cplab2@localhost ~]$ cd csec[cplab2@localhost csec]$ cat file2ijklmnopq[cplab2@localhost ~]$ cp /home/cplab2/csea/file2 /home/cplab2/csed/file2cp: cannot create regular file `/home/cplab2/csed/file2': No such file or directory

2.To copy the contents of a file .While copying it warns the user before overwriting the destination file.

[cplab2@localhost ~]$ cat >file111abcdfe[cplab2@localhost ~]$ cat >file112fdkdij[cplab2@localhost ~]$ cp -i file111 file112cp: overwrite `file112'? y[cplab2@localhost ~]$ cat file112abcdfe

3.To copy an entire directory structure.

[cplab2@localhost ~]$ cp -R csea cseb[cplab2@localhost ~]$ cd cseb

4.To lists all files and directories.

Syntax: ls [options] [filename_spec][cplab2@localhost cseb]$ lscsea file1 file2[cplab2@localhost ~]$ lscollege college1 cse cseb department file111 file12 ATCECollege college2 csea csec file11 file112 file13 ATCE[cplab2@localhost ~]$ cd csea[cplab2@localhost csea]$ lsfile2[cplab2@localhost csea]$ cd ..[cplab2@localhost ~]$ cd cseb[cplab2@localhost cseb]$ lscsea file1 file2

22

5. Removes a file and it ask the user for confirmation before removing each file.

[cplab2@localhost ~]$ cat >file90jfkjdkfdkjfiekdjikedjd[cplab2@localhost ~]$ rm -i file90rm: remove regular file `file90'? y[cplab2@localhost ~]$ cat file90cat: file90: No such file or directory

6. To move a file from one place to another.

Syntax: mv  [options]    old_filename    new_filename[cplab2@localhost ~]$ cat >deptcseeeemechece[cplab2@localhost ~]$ mv dept dept12[cplab2@localhost ~]$ cat dept12cseeeemechece

[cplab2@localhost ~]$ cat deptcat: dept: No such file or directory[cplab2@localhost ~]$ mv dept12 /home/cplab2/csea/dept13[cplab2@localhost ~]$ cd csea[cplab2@localhost csea]$ cat dept13cseeeemechece

7. To lists all files and directories

[cplab2@localhost ~]$ lscollege college1 cse cseb department file111 file12 ATCECollege college2 csea csec file11 file112 file13 ATCE

8. To lists all files and directories including hidden files.

[cplab2@localhost ~]$ ls -a.bashrc college2 csec file111 .kde ATCE college cse department file112 .lesshst .zshrc.bash_logout College csea .emacs file12 .mozilla

22

.bash_profile college1 cseb file11 file13 ATCE

9. To lists all files excluding . and ..

[cplab2@localhost ~]$ ls -A.bash_logout College csea .emacs file12 .mozilla.bash_profile college1 cseb file11 file13 ATCE.bashrc college2 csec file111 .kde ATCEcollege cse department file112 .lesshst .zshrc

10. Lists all files by inode modification time.

[cplab2@localhost ~]$ ls -ccsea file112 csec file13 ATCE college2 ATCE csecseb file111 file12 file11 College college1 college department

11. To lists all in multi-columns.

[cplab2@localhost ~]$ ls -xcollege College college1 college2 cse csea cseb csecdepartment file11 file111 file112 file12 file13 ATCE ATCE

12. To lists all files and sub-directories with time order.

[cplab2@localhost ~]$ ls -tcsea file112 csec file13 ATCE college2 ATCE csecseb file111 file12 file11 College college1 college department

13. To lists all files and sub-directories in reverse order. [cplab2@localhost ~]$ ls -rATCE file13 file112 file11 csec csea college2 CollegeATCE file12 file111 department cseb cse college1 college

14. To lists all file names having non-printable characters.

[cplab2@localhost ~]$ ls -qcollege college1 cse cseb department file111 file12 ATCECollege college2 csea csec file11 file112 file13 ATCE

22

15. To lists files permissions,owner,size,modification time.

[cplab2@localhost ~]$ ls -ltotal 128-rw-rw-r-- 1 cplab2 cplab2 38 Feb 1 11:26 college-rw-rw-r-- 1 cplab2 cplab2 39 Feb 1 11:44 College-rw-rw-r-- 1 cplab2 cplab2 20 Feb 1 11:43 college1-rw-rw-r-- 1 cplab2 cplab2 19 Feb 1 11:43 college2-rw-rw-r-- 1 cplab2 cplab2 12 Feb 1 11:26 csedrwxrwxr-x 2 cplab2 cplab2 4096 Feb 1 12:07 cseadrwxrwxr-x 3 cplab2 cplab2 4096 Feb 1 11:59 csebdrwxrwxr-x 2 cplab2 cplab2 4096 Feb 1 11:52 csec-rw-rw-r-- 1 cplab2 cplab2 26 Feb 1 11:24 department-rw-rw-r-- 1 cplab2 cplab2 8 Feb 1 11:48 file11-rw-rw-r-- 1 cplab2 cplab2 8 Feb 1 11:57 file111-rw-rw-r-- 1 cplab2 cplab2 8 Feb 1 11:58 file112-rw-rw-r-- 1 cplab2 cplab2 8 Feb 1 11:50 file12-rw-rw-r-- 1 cplab2 cplab2 8 Feb 1 11:49 file13-rw-rw-r-- 1 cplab2 cplab2 69 Feb 1 11:32 ATCE-rw-rw-r-- 1 cplab2 cplab2 39 Feb 1 11:44 ATCE

16. Lists all without sorting.

[cplab2@localhost ~]$ ls -fcse .kde file11 .emacs file12 . College.lesshst csea file13 file111 .bash_profile ATCE .mozillacollege .. department college2 college1 .zshrccsec .bashrc file112 cseb ATCE .bash_logout

17. Lists all with size.

[cplab2@localhost ~]$ ls -stotal 1288 college 8 college2 8 cseb 8 file11 8 file12 8 ATCE8 College 8 cse 8 csec 8 file111 8 file138 college1 8 csea 8 department 8 file112 8 ATCE

18. To lists all after sorting with respect to file size.

[cplab2@localhost ~]$ ls -Scsea csec College college college1 cse file111 file12cseb ATCE ATCE department college2 file11 file112 file13

22

(D) DIRECTING OUTPUT TO A FILE

1. To lists all the files on the terminal(screen)

[cplab2@localhost ~]$ ls >mylist[cplab2@localhost ~]$ cat mylistcollegeCollegecollege1college2csecseadepartmentfile11file111file112file12file13mylistATCE

2. To count the number of words,lines and characters in a file.

Syntax: wc [options] filename [cplab2@localhost ~]$ wc mylist 17 17 128 mylist

3. To count the number of lines in a file.

[cplab2@localhost ~]$ wc -l mylist17 mylist

4. To count the number of words in a file.

[cplab2@localhost ~]$ wc -w mylist17 mylist

5. To count the number of characters in a file.

[cplab2@localhost ~]$ wc -c mylist128 mylist

6. To display the type of a file.

[cplab2@localhost ~]$ file mylistmylist: ASCII text[cplab2@localhost ~]$ file csea

22

csea: directory

7. Displays all the files whose name begins with ‘c’.

[cplab2@localhost ~]$ ls c*college college1 college2 csecsea:dept13 file2cseb:csea file1 file2csec:file2

8. Displays all the files whose name begins with c or C.

[cplab2@localhost ~]$ ls [c]*college college1 college2 csecsea:dept13 file2cseb:csea file1 file2csec:file2

9. Displays all the files starting with letter a to d.

[cplab2@localhost ~]$ ls [a-d]*an.txt college College college1 college2 cse departmentcsea:dept13 file2cseb:csea file1 file2csec:file2

10. Displays all the files not starting with letters a to d.

[cplab2@localhost ~]$ ls [!a-d]*file11 file111 file112 file12 file13 mylist ATCE ATCE

22

(E) FILE PERMISSIONS

1. To perform file permissions(u-user,g-group,o-others,r-read,w-write,x-execute)(octal notation for read-4, write-2 ,execute-1)

Syntax: chmod ugo filename[cplab2@localhost ~]$ chmod g=rwx an.txt[cplab2@localhost ~]$ chmod u+rw an.txt[cplab2@localhost ~]$ chmod o-wx an.txt[cplab2@localhost ~]$ ls -l an.txt-rw-rwxr-- 1 cplab2 cplab2 13 Feb 1 13:10 an.txt[cplab2@localhost ~]$ ls -l college-r--r--r-- 1 cplab2 cplab2 38 Feb 1 11:26 college[cplab2@localhost ~]$ chmod u+wx,g=rw,o-r college[cplab2@localhost ~]$ ls -l college-rwxrw---- 1 cplab2 cplab2 38 Feb 1 11:26 college[cplab2@localhost ~]$ ls -l College-rw-rw-r-- 1 cplab2 cplab2 39 Feb 1 11:44 College[cplab2@localhost ~]$ chmod 761 College(user has permission to do all,group has only read and write permission, others has only execute permission)[cplab2@localhost ~]$ ls -l College-rwxrw---x 1 cplab2 cplab2 39 Feb 1 11:44 College[cplab2@localhost ~]$ chmod 463 College[cplab2@localhost ~]$ ls -l College-r--rw--wx 1 cplab2 cplab2 39 Feb 1 11:44 College

22

(F) GENERAL PURPOSE COMMANDS

1.date: To print the date.

[cplab2@localhost ~]$ dateWed Feb 1 13:35:43 IST 2012[cplab2@localhost ~]$ date +%m (To display only month)02[cplab2@localhost ~]$ date +%h (To display month name)Feb[cplab2@localhost ~]$ date +%d (To display day of month)01[cplab2@localhost ~]$ date +%y (To display last two digits of the year)12[cplab2@localhost ~]$ date +%H (To display hours)13[cplab2@localhost ~]$ date +%M (To display minutes)36[cplab2@localhost ~]$ date +%S (To display seconds)42

2.echo: To print the message on the screen, whatever we type on the line.

[cplab2@localhost ~]$ echo computer practice lab II computer practice lab II

3.cal: To display specified month or year calendar.

[cplab2@localhost ~]$ cal (Prints the calendar for the current month of current year) February 2012Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 10 1112 13 14 15 16 17 1819 20 21 22 23 24 2526 27 28 29[cplab2@localhost ~]$ cal 8 2012 (Prints the calendar for the month of August 2012) August 2012Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 10 1112 13 14 15 16 17 1819 20 21 22 23 24 2526 27 28 29 30 31

22

[cplab2@localhost ~]$ cal 2012 (Prints the calendar for the specified year) 2012

4.who: Used to display all the users,who are currently logged into the system.

[cplab2@localhost ~]$ whoroot :0 2012-02-01 11:21cplab2 pts/1 2012-02-01 11:23 (omniplex.uss.sco.com)

5.who am i:Displays a single line of output and lists the user name,terminal line, date and time of login.

[cplab2@localhost ~]$ who am icplab2 pts/1 2012-02-01 11:23 (omniplex.uss.sco.com)[cplab2@localhost ~]$ who –a (Displays everything about all users) 2012-02-01 11:16 429 id=si term=0 exit=0 system boot 2012-02-01 11:16 run-level 5 2012-02-01 11:16 last=S 2012-02-01 11:17 1610 id=l5 term=0 exit=0 2012-02-01 11:17 2544 id=1 2012-02-01 11:17 2547 id=2LOGIN tty3 2012-02-01 11:17 2548 id=3LOGIN tty4 2012-02-01 11:17 2550 id=4 2012-02-01 11:17 2552 id=5 2012-02-01 11:17 2557 id=6 2012-02-01 11:17 2558 id=xroot ? :0 2012-02-01 11:21 ? 2689cplab2 + pts/1 2012-02-01 11:23 . 2898 (omniplex.uss.sco.com)[cplab2@localhost ~]$ who –b (Display the date and time that the system was last rebooted) system boot 2012-02-01 11:16[cplab2@localhost ~]$ who –d (Displays all dead processes) 2012-02-01 11:16 429 id=si term=0 exit=0 2012-02-01 11:17 1610 id=l5 term=0 exit=0[cplab2@localhost ~]$ who –H (Displays verbose column headings)NAME LINE TIME COMMENTroot :0 2012-02-01 11:21cplab2 pts/1 2012-02-01 11:23 (omniplex.uss.sco.com)[cplab2@localhost ~]$ who –m (Displays only our own statistics)cplab2 pts/1 2012-02-01 11:23 (omniplex.uss.sco.com)[cplab2@localhost ~]$ who –q (Gets only the number of users and their login names)root cplab2# users=2

6.finger: Gathers and displays the information about the users,that includes login name, real name, home directory etc.

[cplab2@localhost ~]$ finger cplab2Login: cplab2 Name: (null)

22

Directory: /home/cplab2 Shell: /bin/bashOn since Wed Feb 1 11:23 (IST) on pts/1 from omniplex.uss.sco.comNo mail.No Plan.[cplab2@localhost ~]$ finger (To display the information about all users who are currently logged on.)Login Name Tty Idle Login Time Office Office Phonecplab2 pts/1 Feb 1 11:23 (omniplex.uss.sco.com)root root *:0 Feb 1 11:21

7.id: Used to display the numerical value that corresponds to login name ,i.e.,every valid UNIX user is assigned a login name, a user id and a group-id.

[cplab2@localhost ~]$ iduid=502(cplab2) gid=502(cplab2) groups=502(cplab2) context=user_u:system_r:unconfined_t

8.tty: Used to know the terminal name that we are using.

[cplab2@localhost ~]$ tty/dev/pts/1

9.Command grouping: To execute number of commands in a single line.

[cplab2@localhost ~]$ who && dateroot :0 2012-02-01 11:21cplab2 pts/1 2012-02-01 11:23 (omniplex.uss.sco.com)Wed Feb 1 13:46:34 IST 2012[cplab2@localhost ~]$ who && ls collegeroot :0 2012-02-01 11:21cplab2 pts/1 2012-02-01 11:23 (omniplex.uss.sco.com)college[cplab2@localhost ~]$ who ; dateroot :0 2012-02-01 11:21cplab2 pts/1 2012-02-01 11:23 (omniplex.uss.sco.com)Wed Feb 1 13:47:18 IST 2012[cplab2@localhost ~]$ ls college||college123College

10.Online calculator: To perform online operations

[cplab2@localhost ~]$ bcbc 1.06Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc.This is free software with ABSOLUTELY NO WARRANTY.For details type `warranty'.2+35

11.Filters: A filter is a device file that reads from the standard input and writes to the standard output in a particular format.

Syntax: head [-count] filename[cplab2@localhost ~]$ head mylist (Displays the first ten lines of a file)

22

collegeCollegecollege1college2csecseacsebcsecdepartmentfile11[cplab2@localhost ~]$ head -5 mylist (To display only first 5 lines)collegeCollegecollege1college2cse[cplab2@localhost ~]$ head -13 mylist (To display top 13 lines)collegeCollegecollege1college2csecseacsebcsecdepartmentfile11file111file112file12

12.tail: To display number of lines.

Syntax: tail [-count] filename[cplab2@localhost ~]$ tail mylist (displays 10 lines of a file from the end of the file.)csecdepartmentfile11file111file112file12file13mylistATCEATCE[cplab2@localhost ~]$ tail -5 mylist (Displays last 5 lines of a file)file12file13mylistATCEATCE[cplab2@localhost ~]$ more department mylist (Displays the first screenful information and shows “-more-“ at the end of each page of the file that is being displayed.)

22

::::::::::::::department::::::::::::::cseeceeeemechcivilit::::::::::::::mylist::::::::::::::collegeCollegecollege1college2csecseacsebcsecdepartmentfile11file111file112file12file13mylistATCEATCE

13.sort: To arrange in order.

Syntax: sort filename[cplab2@localhost ~]$ sort department (Used to sort the contents of a file.)civilcseeceeeeitmech[cplab2@localhost ~]$ sort -r department (Sorts and displays the file contents in reverse order.)mechiteeeececsecivil[cplab2@localhost ~]$ cat >citieschennaibangalorebangalorechennai[cplab2@localhost ~]$ sort -u cities (Removes duplicate records)

22

bangalorechennai[cplab2@localhost ~]$ sort -m city cities (Merges sorted files in list.)chennaibangalorechennaibangalorebangalorechennaiHyderabadChennai[cplab2@localhost ~]$ sort -o citty (Places output in file name)

14. Grep:( Global regular expression and print) Used to search and print specified patterns from a file.

Syntax: grep  string file1  [file2 . . .][cplab2@localhost ~]$ cat >countries1India AsiaUSA America[cplab2@localhost ~]$ grep Asia countries (Displays the lines of the file that contains the pattern Asia) .India Asia[cplab2@localhost ~]$ grep America countries

USA America[cplab2@localhost ~]$ grep -i '[A-C]' countries (Displays only the pattern with specified character.)India AsiaUSA America[cplab2@localhost ~]$ nl department (Adds line numbers to a file) 1 cse 2 ece 3 eee 4 mech 5 civil 6 it[cplab2@localhost ~]$ cut -c2 department (To select specified fields from a line of text.Here it cuts only the second character of each line from the file department.)sceeit[cplab2@localhost ~]$ paste department (After cut, those can be pasted back .)cseeceeeemechcivilit[cplab2@localhost ~]$ cat>file1

22

abcdefhgiakdidkike[cplab2@localhost ~]$ cat>file2fkieancdgkieddekabcd[cplab2@localhost ~]$ cmp file1 file2 (Checks whether two files are identical in all respects so that one of them may be deleted.)file1 file2 differ: byte 1, line 1When two files are identical, it won’t display any message.[cplab2@localhost ~]$ cmp -l file1 file2 (Displays the list of byte number and the differing bytes in octal notation for each character that differs in both of the files.) 1 141 146 2 142 153 3 143 151 4 144 145 6 145 141 7 146 156 8 150 143 9 147 14410 151 1211 12 14712 141 15313 153 15114 144 14515 151 1216 12 144cmp: EOF on file1[cplab2@localhost ~]$ comm file1 file2 (Used to compare two sorted files, and compares each line fo the first file with its corresponding line in the second.It displays a three columnar output.First- unique to the first file,Second- unique to the second file,Third-Common to both files.)abcdefhgiakdidkikefkieancdgkieddekabcd

15.diff: Display file differences and tells which lines in one file have to be changed to make the two files identical.

Syntax: diff [options] file1   file2[cplab2@localhost ~]$ diff file1 file2 0a1,4> fkie> ancd> gkie

22

> ddek2,4d5< efhgi< akdi< dkikePIPES: A mechanism by which output of one command can be channeled into the input of another command. The pipe symbol is the vertical line, |, on your keyboard.[cplab2@localhost~]who | wc –l2

16.Transfer data between devices/users:

Mesg: Used to send message to another user’s terminal.Write: Used to communicate with other users that are logged in at the same time.Wall: Used to send message to all users.News: Permits users to read messages published on the system administrator.Mail: Used to send mail to other users.Reply: Used to give reply to the user.[cplab2@localhost ~]$ mesg hello // send message to all terminals[cplab2@localhost ~]$ write cse188 // send message to particular user hi(ctrl+d)[cplab2@localhost ~]$ wall message // send all usersHi how r u(ctrl +d)[cplab2@localhost ~]$ news //send any message by system admin

22

(G) Disk Usage

1. The df command

To lists the current total disk usage for all file systems accessible by your workstation. Syntax: df -k

2. The du command

To determine your current disk quota usage, use the du command. Syntax: du [options] directory

By default, the du command by itself will give a summary of quota usage for the directory specified and all subdirectories below it.

du /users/usernameFor a summary of total disk usage, use the -s option.

du -s /users/usernameFor a summary of your own disk usage, enter

du -s ~

3.The man command

To obtain information on any Unix command, use the on-line manual pages. Syntax: man command

If you do not know the name of the actual command you need, execute man with the -k option.         man -k keywordFor example, to find out all the commands related to directories, type         man -k directory

4. The uniq command

To get one copy of the redundant record to the standard output.

[cplab2@localhost ~]$ cat> abbfhifhi[cplab2@localhost ~]$ uniq abb

22

(H) I/O REDIRECTION

1.Redirecting standard output to a file:

Syntax: command>fileThe output of the command is stored in the file and the output is not shown on the screen.If the file does not exist, it is created. If it does exist,it is cleared and refilled with new data.[cplab2@localhost ~]$ ls >myfileRedirects the output to the end of the file.[cplab2@localhost ~]$ ls>>myfile

2.Reading standard input from a file.

Syntax: command<file It reads input from the specified file.[cplab2@localhost ~]$ cat < departmentcseeceeeemechcivilit[cplab2@localhost ~]$ cat departmentcseeceeeemechcivilit

3.Redirecting standard error:

Syntax: command>errorfileIncludes all the error messages written to the terminals.[cplab2@localhost ~]$ cat hfk > errorfilecat: hfk: No such file or directory

4.Combining standard input and output:

Syntax: command <file>file2[cplab2@localhost ~]$ wc <department> abb[cplab2@localhost ~]$ cat abb6 6 26[cplab2@localhost ~]$ wc > department <abb[cplab2@localhost ~]$ cat abb 6 6 26[cplab2@localhost ~]$ cat department

1 3 9[cplab2@localhost ~]$ wc >ant1<ant

22

[cplab2@localhost ~]$ cat ant1 4 4 22[cplab2@localhost ~]$ cat antabcdefghi'\00'fkjf[cplab2@localhost ~]$ wc >ant<ant1[cplab2@localhost ~]$ cat ant1 3 9[cplab2@localhost ~]$ cat ant14 4 22

5.Passwd: To change the password

[cplab2@localhost ~]$ passwdChanging password for user cplab2.Changing password for cplab2(current) UNIX password:New UNIX password:

6.History: Lists commands we have done recently.

7. Sed:( Stream Editor-Command line processing of data files)

Print the specified number of lines of a file from start to end of the file.[cplab2@localhost ~]$ sed -n '3,5p' department

8. To convert from upper case to lower case:

[cplab2@localhost ~]$ cat > file123kdjfdkdjfd[cplab2@localhost ~]$ tr "[:lower:]" "[:upper:]" < file123KDJFDKDJFD

9.To convert from lower to upper case:[cplab2@localhost ~]$ cat >file456ABCDEFGHIKE[cplab2@localhost ~]$ tr "[:upper:]" "[:lower:]" < file456abcdefghike[cplab2@localhost ~]$ tr '[a-z]' '[A-Z]' <file456ABCDE

22

SHELL PROGRAMMING

22

FIND THE GIVEN NUMBER ISEVEN OR ODD

AIM: To find the given number is even or odd

ALGORITHM:

1. Start2. Read a number3. Write a even number, else4. Write a odd number5. Stop

PROGRAM

echo " Enter number"read am=`expr $a % 2`if [ $m -eq 0 ]thenecho "Even"elseecho "Odd"fi

OUTPUT:

[cplab2@localhost shell]$ sh odd.shEnter number3Odd

[cplab2@localhost shell]$ sh odd.shEnter number 6Even

RESULT:

22

LEAP YEAR

AIM: To find the given year is a leap year or not

ALGORITHM:

1. Start2. Read a year3. Write a leap year, else4. Write a not leap year5. Stop

PROGRAM:

echo " Enter the year "read am=`expr $a % 4`if [ $m -eq 0 ]thenecho "Leap year"elseecho "Not leap year"fi

OUTPUT:

[cplab2@localhost shell]$ sh leap.shEnter number2000Leap year[cplab2@localhost shell]$ sh leap.shEnter number2001Not leap year

RESULT:

22

AREA AND CIRCUMFERERNCEOF THE CIRCLE

AIM:

To find area and circumference of the circle.

ALGORITHM:1. Start2. Read the radius3. Find area and circumference of the circle

Area=3.14*radius*radiusCircumference=2*3.14*radius

4. Stop

PROGRAM:

echo "Enter radius"read rarea=$(echo "3.14*$r*$r"|bc)circum=$(echo "2*3.14*$r"|bc)echo $area ,$circum

OUTPUT:

[cplab2@localhost shell]$ sh area.shenter radius328.26 ,18.84

RESULT:

22

PALINDROME

AIM:

To find the given number is palindrome or not

ALGORITHM:

1. Start2. Read a number3. Write a palindrome number , else4. Write a not palindrome number5. Stop

PROGRAM:

echo "Enter number"read nrev=0x=$nwhile [ $n -gt 0 ]dod=`expr $n % 10`rev=$(echo "$rev*10+$d"|bc)n=`expr $n / 10`doneif [ $x -eq $rev ]thenecho "Palindrome"elseecho "Not palindrome"fi

OUTPUT:

[cplab2@localhost shell]$ sh palindrome.shEnter number123Not palindrome[cplab2@localhost shell]$ sh palindrome.shEnter number121Palindrome

RESULT:

22

QUADRATIC EQUATION

AIM:

To find the roots of the quadratic equation

ALGORITHM:

1. Start2. Enter the three numbers 3. Read a, b, c4. Read r1, r2 values, else5. Display “roots are imaginary”6. Stop

PROGRAM:

echo "Enter three number"read a b cd=$(echo "$b*$b-(4*$a*$c)"|bc)x=$(echo "sqrt($d)"|bc)y=$(echo " -1*$b"|bc)if [ $d -gt 0 ]thenr1=$(echo "scale=2;($y+$x)/2*$a"|bc) (0r) r1=`expr $y + $x / 2 \* $a`r2=$(echo "scale=2;($y-$x)/2*$a"|bc) (or) r2=`expr $y - $x / 2 \* $a` echo $r1 ,$r2elseecho "Roots are imaginary"fi

OUTPUT:

[cplab2@localhost shell]$ sh quad.shEnter three number1 -3 -44.00 ,-1.00[cplab2@localhost shell]$ sh quad.shenter three number1 0 9Roots are imaginary

RESULT:

22

ARMSTRONG NUMBER

AIM:

To check the given number is Armstrong or not.

ALGORITHM:

1. Start2. Enter a number3. Read a number4. Write Armstrong number, else5. Write a not Armstrong number6. Stop

PROGRAM:

echo "Enter number"read nsum=0x=$nwhile [ $n -gt 0 ]dod=`expr $n % 10`sum=`expr $sum + $d \* $d \* $d` (or) n=`expr $n / 10`doneif [ $x -eq $sum ]thenecho "Armstrong no"elseecho "Not Armstrong"fi

OUTPUT:

[cplab2@localhost shell]$ sh armstrong.shEnter number153armstrong no[cplab2@localhost shell]$ sh armstrong.shEnter number123Not Armstrong

RESULT:

22

PRIME NUMBER

AIM:

To check the given number is prim or not

ALGORITHM:

1. Start2. Enter a number3. Read a number4. Write a prime number, else5. Write not prime number6. Stop

PROGRAM:

echo "Enter number"read nfor((i=2;i<=n-1;i++))do x=`expr $n % $i` (or) if [ $x -eq 0 ]thenecho "Not Prime"exitfidoneecho "Prime"

OUTPUT:

[cplab2@localhost shell]$ sh prime.shEnter number4Not Prime [cplab2@localhost shell]$ sh prime.shEnter number89Prime

RESULT:

COMMAND EXE IN CASE

x=$(echo "$n%$i"|bc)

22

AIM: To study basic Unix commands exe in case

PROCEDURE:

1. who To show the users currently logged on.

2. ls

To list out the names of cell files to be current working directory

3. date To display to be current date and time

4. id To display the numerical value that corresponds to login name.

5. exit To come out from the terminals.

PROGRAM:

echo "Enter ur choice 1.who 2.ls 3.date 4.id 5.exit"read chcase $ch in1)who;;2)ls;;3)date;;4)id;;5)exit;;esac

22

OUTPUT:

[cplab2@localhost shell]$ sh command.shEnter ur choice 1.who 2.ls 3.date 4.id 5.exit1exam03 pts/31 Feb 7 08:31 (132.147.162.40)[cplab2@localhost shell]$ sh command.shEnter ur choice 1.who 2.ls 3.date 4.id 5.exit2add.sh area.shwq big3.sh case.sh command.sh leap.sh positive.sharea.sh arith.sh big.sh circle.sh equal.sh odd.sh[cplab2@localhost shell]$ sh command.shEnter ur choice 1.who 2.ls 3.date 4.id 5.exit3Tue Feb 7 11:05:11 IST 2012[cplab2@localhost shell]$ sh command.shEnter ur choice 1.who 2.ls 3.date 4.id 5.exit4uid=504(exam03) gid=504(exam03) groups=504(exam03) context=user_u:system_r:unconfined_t[cplab2@localhost shell]$ sh command.shEnter ur choice 1.who 2.ls 3.date 4.id 5.exit5

RESULT:

22

STUDENT GRADE

AIM:

To calculate the total marks of a student.

ALGORITHM:

1. Start2. Enter the marks of the student3. Read m1, m2, m3, m4, m54. Calculate total marks and average mark5. Display the grade6. Stop

PROGRAM:

echo "Enter five marks"read m1 m2 m3 m4 m5total=$(echo "$m1+$m2+$m3+$m4+$m5"|bc)avg=$(echo "$total/5"|bc)echo $total,$avgif [ $m1 -lt 50 -o $m2 -lt 50 -o $m3 -lt 50 -o $m4 -lt 50 -o $m5 -lt 50 ]thenecho "fail"elif [ $avg -ge 90 ]thenecho "S GRADE"elif [ $avg -ge 80 ]thenecho "A GRADE"elif [ $avg -ge 70 ]thenecho "B GRADE"elif [ $avg -ge 60 ]thenecho "C GRADE"elseecho "D GRADE"fi

22

OUTPUT:

[cplab2@localhost shell]$ sh studgrade.shEnter five marks90 80 50 60 30310,62fail[cplab2@localhost shell]$ sh studgrade.shEnter five marks90 80 60 90 90410,82A GRADE

RESULT:

22

FACTORIAL NUMBER

AIM:

To find the factorial of a number

ALGORITHM:

1. Start2. Enter the number3. Read a factorial number4. Display the factorial value5. Stop

PROGRAM:

echo "Enter number"read nfact=1for((i=1;i<=$n;i++))dofact=`expr $fact \* $doneecho $fact

OUTPUT:

[cplab2@localhost shell]$ sh fact.sh Enter number 5 120

RESULT:

22

FIBONACCI SERIES

AIM: To find the Fibonacci series values for the given data

ALGORITHM:

1. Start2. Enter the number3. Read N value4. Display the Fibonacci series 5. Stop

PROGRAM :

echo "Enter number"read na=-1b=1echo "Fibonacci series "for((i=1;i<=$n;i++))doc=$(echo "$a+$b"|bc)echo $ca=$bb=$cdone

OUTPUT:

[cplab2@localhost shell]$ sh fibonacci.shEnter number8Fibonacci series011235813

RESULT:

22

ARITHMETIC OPERATION

AIM: To find the arithmetic operation for the given Arithmetic expression (ADD, SUB, MUL, DIV)

ALGORITHM:

1. Start2. Enter the values A,B 3. Read a, b 4. Display output for given expression 5. Stop

PROGRAM :

echo "Enter two number"read a becho "Enter two number"read a bc=`expr $a + $b`d=`expr $a - $b`e=`expr $a \* $b` f=`expr $a / $b`echo $c, $d, $e, $f

OUTPUT:

[cplab2@localhost shell]$ sh arith.shEnter two number3 47, -1, 12, 0

RESULT:

22

NATURAL NUMBER

AIM: To find the natural number for given value.

ALGORITHM:

1. Start2. Enter the value n 3. Read the value n4. Display the natural number for n value5. Stop

PROGRAM :

echo "Enter number"read ni=1while [ $i -le $n ]doecho $ii=`expr $i + 1`done

OUTPUT:

[cplab2@localhost shell]$ sh natural.shEnter number812345678

RESULT:

22

FUNCTION WITHOUT ARGUMENTS

AIM: To find the without arguments for the given two value ALGORITHM:

1. Start2. Enter the value a,b 3. Read the value a,b 4. Display the c values using without arguments5. Stop

PROGRAM :

add(){c=`expr $a + $b`return $c}echo "Enter two number"read a baddecho $?

OUTPUT:

[cplab2@localhost shell]$ sh sum2.shEnter two numbers5 611

RESULT:

22

C- PROGRAMMING

22

ADDING TWO NUMBERS USING COMMAND LINE ARGUMENT

AIM: To using command line argument of adding two numbers ALGORITHM:

1. Start2. Enter the arguments for two values3. Read the value a,b values4. Display the arguments for two values5. Stop

PROGRAM :

#include <stdio.h>main(int argc,char *argv[]){int c;c=atoi(argv[1])+atoi(argv[2]);printf("number of argument is %d",argc);printf("addition is %d",c);}

OUTPUT:

[cplab2@localhost c]$ cc add1.c -o add1[cplab2@localhost c]$ ./add1 2 7 8 6

number of argument is 5addition is 9

RESULT:

22

SWAPPING OF TWO NUMBERS USING FUNCTION WITH POINTER

AIM: To find swapping of two numbers using function with pointer.

ALGORITHM:

1. Start2. Enter the value a,b values3. Read the value a,b values4. Display the swapping of two numbers 5. Stop

PROGRAM :

#include<stdio.h>int swap(int *a,int *b){int c;c=*a;*a=*b;*b=c;printf("%d%d",*a,*b);}main(){int x,y,z;printf("Enter two number");scanf("%d%d",&x,&y);swap(&x,&y);return 0;}

OUPUT:

[cplab2@localhost c]$ cc swap.c -o swap[cplab2@localhost c]$ ./swapEnter two number7 88 7

RESULT:

22

FILE COPY

AIM: To copy the file from the drive.

ALGORITHM:

1. Start2. To create the file before compile.3. get the file from the drive 4. show the file from current drive5. stop

PROGRAM :

#include<stdlib.h>main(){FILE *f1,*f2;int ch;f1=fopen("first.txt","r");f2=fopen("second.txt","w");

if(f1==NULL){printf("file not found");exit;}

while((ch=fgetc(f1))!=EOF){fputc(ch,f2);putc(ch,stdout);}fclose(f1);fclose(f2);return 0;}

22

OUPUT:

Before compile:

[cplab2@localhost c]$ vi first.txthaiwelcome

compilation:

[cplab2@localhost c]$ cc file1.c -o file[cplab2@localhost c]$ ./file1haiwelcome

After compile:

[cplab2@localhost c]$ vi second.txthaiwelcome

RESULT:

22

FILE MERGE

AIM: To merge the file from the given data. ALGORITHM:

1. Start2. Merge the file content after compile 3. To merge the file content in the file 4. stop

PROGRAM :

#include<stdio.h>#include<stdlib.h>main(){FILE *f1,*f2,*f3;int ch;f1=fopen("one.txt","r");f2=fopen("two.txt","r"); f3=fopen("three.txt","w");if(f1==NULL){printf("File not found");exit;}if(f2==NULL){printf("file not found");}while((ch=fgetc(f1))!=EOF){fputc(ch,f3);putc(ch,stdout);}while((ch=fgetc(f2))!=EOF){fputc(ch,f3);putc(ch,stdout);}fclose(f1);fclose(f2);fclose(f3);return 0;}

22

OUTPUT:

Before compile:

[cplab2@localhost c]$ vi one.txtgood[cplab2@localhost c]$ vi two.txtMorning

compilation:

[cplab2@localhost c]$ cc filemerge.c -o filemerge[cplab2@localhost c]$ ./filemergegoodmorning

After compile:

[cplab2@localhost c]$ vi three.txtgoodmorning

RESULT:

22

MEMORY REALLOCATION (MALLOC,REALLOC,FREE)

AIM: To find memory allocation of Malloc, Realloc,Free

ALGORITHM:

1. Start2. Reallocate the memory 3. Display content of another data from same memory4. Stop

PROGRAM :

#include<stdio.h>#include<stdlib.h>#include<string.h>main(){char *p;p=(char *)malloc(2);strcpy(p," CSE");printf("%s",p);p=(char *)realloc(p,22);strcpy(p," COMPUTER SCIENCE AND ENGG ");printf("%s",p);printf("after free");free(p); printf("%s",p);return 0;}

OUTPUT:

[cplab2@localhost c]$ cc realloc.c -o realloc[cplab2@localhost c]$ ./reallocCSECOMPUTER SCIENCE AND ENGGafter free (nothing is display)

RESULT:

22

MATRIX MULTIPLICATION USING DYNAMIC MEMORY ALLOCATION(CALLOC( ) )

AIM: To find matrix multiplication using dynamic memory

ALGORITHM:

1. Start2. Enter the no of rows and columns 3. Enter the A matrix rows and column4. Enter the B matrix rows and column5. Get the result for multiple matrix6. Stop

PROGRAM :

#include<stdio.h>#include<stdlib.h>main(){int **a,**b,**c,r1,c1,i,j,k;printf("Enter the no of rows,columns");scanf("%d%d",&r1,&c1);a=(int **)calloc(sizeof(int *),r1);b=(int **)calloc(sizeof(int *),r1);c=(int **)calloc(sizeof(int *),r1);for(i=0;i<r1;i++){ a[i]=(int *)calloc(sizeof(int),c1); b[i]=(int *)calloc(sizeof(int),c1); c[i]=(int *)calloc(sizeof(int),c1); }printf("Enter A matrix elements");for(i=0;i<r1;i++)for(j=0;j<c1;j++)scanf("%d",&(a[i][j]));printf("Enter B matrix elements");for(i=0;i<r1;i++)for(j=0;j<c1;j++)scanf("%d",&(b[i][j]));for(i=0;i<r1;i++){ c[i][j]=0;for(j=0;j<c1;j++){for(k=0;k<c1;k++)

22

{ c[i][j]=c[i][j]+a[i][k]+b[k][j];}}}

printf("Matrix multiplication is");for(i=0;i<r1;i++){printf("\n");for(j=0;j<c1;j++){printf("\t %d",c[i][j]);}}return 0;}

OUTPUT:

[cplab2@localhost c]$ cc matmul.c -o matmul[cplab2@localhost c]$ ./matmulEnter the no of rows,columns 2 2Enter A matrix elements1 23 4Enter B matrix elements5 67 8Matrix multiplication is15 1719 21

RESULT:

22

TRANSPOSE OF MATRIX USING DYNAMIC MEMORY ALLOCATION (CALLOC( ))

AIM: To find the transpose of matrix using dynamic memory allocation (calloc( )) ALGORITHM:

1. Start2. Enter the rows and column 3. Enter the A matrix rows and column 4. Get the result for transpose matrix5. Stop

PROGRAM :

#include<stdio.h>#include<stdlib.h>main(){int **a,r1,c1,i,j;printf("Enter the no of rows,columns");scanf("%d%d",&r1,&c1);a=(int **)calloc(sizeof(int *),r1);for(i=0;i<r1;i++){a[i]=(int *)calloc(sizeof(int),c1);}printf("Enter A matrix elements");for(i=0;i<r1;i++)for(j=0;j<c1;j++)scanf("%d",&(a[i][j]));printf("Transpose of matrix is");for(i=0;i<r1;i++){printf("\n");for(j=0;j<c1;j++){printf("\t %d",a[j][i]);}}return 0;}

22

OUTPUT:

[cplab2@localhost c]$ cc mattranspose.c -o mattranspose[cplab2@localhost c]$ ./mattransposeEnter the no of rows,columns 3 3Enter A matrix elements2 3 45 6 78 9 1Transpose of matrix is2 5 83 6 94 7 1

RESULT:

22

MATRIX ADDITION USING DYNAMIC MEMORY ALLOCATION(CALLOC( ) )

AIM: To find the matrix addition using dynamic memory allocation(calloc( ) )

ALGORITHM:

1. Start2. Enter the row and column3. Read a matrix and b matrix values4. Get the values for the matrix addition 5. Stop

PROGRAM :

#include<stdio.h>#include<stdlib.h>main(){int **a,**b,**c,r1,c1,i,j;printf("Enter the no of rows,columns");scanf("%d%d",&r1,&c1);a=(int **)calloc(sizeof(int *),r1);b=(int **)calloc(sizeof(int *),r1);c=(int **)calloc(sizeof(int *),r1);for(i=0;i<r1;i++) { a[i]=(int *)calloc(sizeof(int),c1); b[i]=(int *)calloc(sizeof(int),c1); c[i]=(int *)calloc(sizeof(int),c1);}printf("enter A matrix elements");for(i=0;i<r1;i++)for(j=0;j<c1;j++)scanf("%d",&(a[i][j]));printf("Enter B matrix elements");for(i=0;i<r1;i++)for(j=0;j<c1;j++)scanf("%d",&(b[i][j]));for(i=0;i<r1;i++)for(j=0;j<c1;j++)c[i][j]=a[i][j]+b[i][j];printf("matrix additon is");for(i=0;i<r1;i++){printf("\n");for(j=0;j<c1;j++){

22

printf("\t %d",c[i][j]);}}return 0;}

OUTPUT:

[cplab2@localhost c]$ cc matadd.c -o matadd[cplab2@localhost c]$ ./matadd

Enter the no of rows,columns 2 3Enter A matrix elements2 5 14 5 6

Enter B matrix elements7 1 26 5 3

Matrix additon is9 6 310 10 9

RESULT:

22

SORTING THE ELEMENTS USING DYNAMIC MEMORY ALLOCATION(MALLOC() )

AIM: To find the sorting the elements using dynamic memory

ALGORITHM:

1. Start2. Enter the elements using dynamic memory3. Read the value 4. Sorting the elements from reallocation 5. Stop

PROGRAM :

#include<stdio.h>#include<stdlib.h>main(){int *a,n,i,j,t;printf("Enter the no of elements");scanf("%d",&n);a=(int *)malloc(n * sizeof(int));printf("Enter the elements");for(i=0;i<n;i++){scanf("%d",&a[i]);}for(i=0;i<n-1;i++)for(j=i+1;j<n;j++)if(a[i]>a[j]){t=a[i];a[i]=a[j];a[j]=t;}printf("Sorted elements");for(i=0;i<n;i++){printf("\n%d",a[i]);}return 0;}

22

OUTPUT

[cplab2@localhost c]$ cc sort.c -o sort[cplab2@localhost c]$ ./sortEnter the no of elements 5Enter the elements 45 56 7 12 1Sorted elements17 12 4556

RESULT:

22

BIGGEST AMONG ‘N’ NUMBERS USING FUNCTIONS

AIM:

To write a C program to find biggest among list of numbers.

ALGORITHM:

1. Get the value of n as input. 2. Get the list of numbers in an array of size n. 3. Set the initial value as a biggest value. 4. Set the value of I is 1. 5. Compare it with other elements in an array. 6. If the biggest element is less than array element then interchange both the values. 7. Repeat steps 4 & 5 until I reaches n-1. 8. Display the biggest value.

PROGRAM:

#include<stdio.h>#include<conio.h>float largest(float a[],int n);void main() {int n;float value[10];clrscr();printf("enter the value of n\n");scanf("%d",&n);for(i=0;i<n;i++) {scanf("%f",&value[i]); }printf("The Largest number among set of numbers is\n");printf("%f",largest(value,n));getch(); }float largest(float a[],int n) {int i;float max;max=a[0];for(i=1;i<n;i++) {if(max<a[i]) {max= a[i]; } }return(max);

22

}

OUTPUT:

[cplab2@localhost c]$ cc big.c -o big[cplab2@localhost c]$ ./big

enter the value of n 5 20 40 38 29 17 The Largest number among set of numbers is 40

RESULT:

22

PALINDROME CHECKING

AIM:

To check whether the given string is palindrome or not using Command linesubstitution.

ALGORITHM:

1. Get the filename and string in a command line. 2. Reverse the original string. 3. If the original string is equal to the reversed string then display a given string is palindrome. 4. Otherwise display a given string is not palindrome.

PROGRAM:

#include<stdio.h>#include<string.h>vidyarthiplus.comvidyarthiplus.comvoid main(intargc, char *argv[]){charstr[10],revstr[10];inti,len,j=0;if(argc !=3) {printf("\n Parameters missing");exit(0); }strcpy(str,argv[2]);len=strlen(argv[2]);for(i=len;i>= 0;i--) {revstr[j]=str[i-1];j++; }if(strcmp(revstr,str)==0)printf("\nPalindrome\n");elseprintf("\nNot palindrome\n");}

OUTPUT:

[cplab2@localhost c]$ cc outpaly.c -o outpaly[cplab2@localhost c]$ a.outpaly.c madam Palindrome[cplab2@localhost c]$ a.outpaly.c sit Not palindrome

RESULT: Thus the c program palindrome checking output was successfully verified.

22

CONCATENATION OF TWO STRINGS

AIM:

To concatenate given two strings using Command line substitution.

ALGORITHM:

1. Get the two strings in command line. 2. Copy the two arguments in two variables from the command line. 3. Concatenate the two strings using the built – in concatenate function. 4. Display the resultant string.

PROGRAM:

#include <stdio.h>#include <string.h>main(intargc, char *argv[]){char str1[10],str2[20],str3[10];strcpy(str1,argv[1]);vidyarthiplus.comvidyarthiplus.comstrcpy(str2,argv[2]);printf("%s",strcat(str1,str2));}

OUTPUT:

[cplab2@localhost c]$ cc concat.c -o concat[cplab2@localhost c]$ a.outconcat.c RMK CET RMKCET

RESULT:

22

MARK AGGREGATE

AIM:To write a C program to find dynamic memory allocation mark aggregate.

ALGORITHM:

1 . Read number of students, say n 2 . Request memory dynamically to store marks of n students using malloc and store the address in a 3 . If requested block of memory is not allocated then Stop 4 . Set up a loop and read array elements ai 5 . Initialize sum to 0 6 . Set up a loop and array elements ai to sum 7 . Compute mark aggregate and display it 8 . Release the requested memory 9 . Stop.

PROGRAM:

#include <stdlib.h>#include <malloc.h>#include <stdio.h>main(){int n, i, *a;floatavg, sum=0;printf("Enter the No. of students : ");scanf("%d", &n); a = (int*) malloc(n * sizeof(int));if (a == NULL) {printf("\n memory allocations not possible");exit(-1); }printf("Enter %d marks : ", n);for(i=0; i<n; i++) {scanf("%d",&a[i]); }for(i=0; i<n; i++)sum += a[i];avg = sum / n;printf("Average mark : %.2f\n",avg);free(a);}

22

OUTPUT:[cplab2@localhost c]$ cc mark.c -o mark[cplab2@localhost c]$ ./mark

Enter the No. of students : 6Enter 6 marks: 56 67 78 89 90 98Average mark: 79.67

RESULT: