You are on page 1of 27

EX NO: 1 DATE: STUDY OF UNIX OPERATING SYSTEM AIM To introduce the concept of UNIX Operating System OPERATING SYSTEM

An Operating System is a set of programs that 1. Functions as an virtual machine by presenting an interface that is easier to program than the underlying hardware 2. Acts as resource management through orderly and controlled allocation of the processors, memories, and I/O devices among the programs competing for it. OS TYPES 1. Single UserThe system will have its own hard disk, memory, CPU and other resources all dedicated to a single user. Eg. MS-DOS 2. Multi UserThe users having access to a multi-user system will have just a terminal and a keyboard. The other resources such as hard disk, printers are centrally located. The user is expected to simply hook onto his account, perform the work, disconnect and leave quietly. Eg. UNIX UNIX HISTORY The spade work for UNIX began at AT&T Bell Laboratories in 1969 by Ken Thompson and Dennis Ritchie. The OS was initially known as UNICS (jokingly UNiplexed Information and Computing System). In 1970 UNICS finally became UNIX. In 1973, UNIX was rewritten in 1973 in C principally authored by Ritchie. UNIX FEATURES 1. Multi-user systemMulti-user capability of UNIX allows several users to use the same computer to perform their tasks. Several terminals [Keyboards and Monitors] are connected to a single powerful computer [UNIX server] and each user can work with their terminals. 2. Multi-tasking systemMultitasking is the capability of the operating system to perform various task simultaneously, i.e. a user can run multiple tasks concurrently. 3. Programming FacilityUNIX is highly programmable, the UNIX shell has all the necessary ingredients like conditional and control structures, etc. 4. SecurityUNIX allows sharing of data; every user must have a single login name and password. So, accessing another users data is impossible without his permission. 5. PortabilityUNIX is portable because it is written in a high level language. So, UNIX can be run on different computers. 6. CommunicationUNIX supports communication between different terminals of the same server as well as between terminals on different servers. Apart from these features, UNIX has an extensive Tool kit, exhaustive system calls and Libraries and enhanced GUI (X Window). ORGANIZATION OF UNIX The UNIX system is functionally organized at three levels and are:

1. The kernel, which schedules tasks and manages storage; 2. The shell, which connects and interprets users' commands, calls programs from memory, and executes them; and 3. The tools and applications that offer additional functionality to the OS

The kernel is the heart of the system, a collection of programs written in C that directly communicate with the hardware. There is only one kernel for any system. It's that part of UNIX system that is loaded into memory when the system is booted. It manages the system resources, allocates time between user and processes, decides process priorities, and performs all other tasks. The kernel, in traditional parlance, is often called the Operating system. The shell, on the other hand, is the "sleeping beauty" of UNIX. It is actually the interface between the user and the kernel. The shell is the agency which takes care of the features of redirection and has a programming capability of its own.

The Tools and Applications consist of Application Software, Compilers, Database Package, Internet tools, UNIX commands, etc. FILE SYSTEM A file in UNIX is nothing but a storehouse of information and everything is treated as a file by UNIX. The files can be broadly classified as follows: Ordinary filesContains stream of data. All data, text, source programs, object and executable code, commands fall into this category. Directory filesContains no external data. It contains an entry, name of the file and its inode (identification number) for each file and subdirectory under that directory. Directory files are not created by the user but by the UNIX system itself. Device filesEven physical devices are treated as files. These are special in the sense that any output directed to it will be reflected onto the respective device.

UNIX FILE SYSTEM All files in UNIX are related to one another. The file system of UNIX resembles a tree that grows from top to bottom as shown in the figure. The file system begins with a directory called root (at the top). The root directory is denoted by a slash (\). Branching from root there

are several directories such as bin, lib, etc, tmp, dev. Each of these directories contains several sub-directories and files. RESULT: Thus the study of UNIX Operating System has been completed successfully. EX NO:2 DATE: BASIC UNIX COMMANDS AIM: To execute and implement the basic Shell UNIX Commands 1. DIRECTORY HANDLING COMMANDS $ mkdir arun ---create a directory named arun $ cd arun ---Enter into the directory arun /arun$ cd ---changing the current working directories $ rmdir cc --remove directory /arun$ pwd ---shows the present working directory /home/nirmala/arun /arun$ ls --Shows the list of files and directories aa bb /arun$ ls -l ---list the permission of files/directories total 8 drwxr-xr-x 2 nirmala nirmala 4096 2012-01-13 01:04 aa drwxr-xr-x 2 nirmala nirmala 4096 2012-01-13 01:05 bb $ tput clear ---clear the screen and places a $ prompt at the top left corner of the screen RESULT: Thus the directory commands were executed successfully. 2. FILE HANDLING COMMANDS catthis create,veiw and concate files creation: syn: $cat>filename ex: $ cat>bala hai viewing: syn:$cat filename ex: $ cat bala hai add text to an existing file: syn: $ cat>>filename ex: $ cat>>bala bye concatenate:

syn: $cat file1 file2>file3 ex:$ cat bala vaishali>raja $ cat raja hai bye bye grepused to search a particuler word or pattern related to that word from the file syn: $grep searchword filename ex: $ grep hai raja hai rmdeletes a file from the file system syn:$rm filename ex: $ rm raja touch used to create a blank file. Syn: $ touch file names ex: $ touch channu cp copies the files or directories syn: $ cp source file destination file eg: $ cp vaishali channu mv to rename the file or directory syn: $ mv old file new file Ex:$ mv vaishali hari cut it cuts or pick up a given number of character or fields of the file. Syn: $ cut <option> <filename> Eg: $ cut c filename $ cut c 1 -10 emp $ cut f 3,6 emp Paste - It concatenates the line from each input file column by column with tab characters in between them. Syntax : paste [options] <file name > Example : $ paste f1 f2 Join - It is used to extracts common lines from two sorted files and there should be the common field in both file. Syntax : join [options] <file name1 > <file name 2>

Example

: $ join a1 f1 f2

Uniq - It compares adjacent lines in the file and displays the output by eliminating duplicate adjacent lines in it. Syntax : uniq [options] <file name > Example : $ uniq -c aa 1 ravi 1 priya

Sort - It sorts one or more files based on ASCII sequence and also to merge the file. Syntax : sort [options] <file name > Example : $ sort -r aa ravi priya Nl - It is used to add the line numbers to the file. Syntax : nl [options] [filename] Example : $ nl aa 1 ravi 2 priya head displays 10 lines from the head (top) of a given file syn: $ head filename eg: $ head aa ravi priya To display the top two lines: $ head -2 aa tail displays last 10 lines of the file syn: $ tail filename eg: $ tail aa ravi priya To display the bottom two lines; $ tail -2 aa wc it counts the number of lines, words, character in a specified file(s) with the options as l, -w, -c syn: $wc l filename $wc w filename

$wc c filename Ex: $ wc -l aa 2 aa $ wc -w aa 2 aa $ wc -c aa 11 aa More -- It is used to display the contents of the file on the screen at a time. Syntax : more <file name > Example : $ more aa ravi priya File -- It is used to determine the type of the file. Syntax : file <file name > Ex: $ file aa aa: ASCII text

Split - It is used to split the given file into smaller pieces of given size. Syntax : split size <file name > < splitted file name > Example : $ split 2 aa a chmod used to change the permissions of a file or directory. Syn: $ chmod category operation permission file Where, category is the user type Operation is used to assign or remove permission Permission is the type of permission File are used to assign or remove permission Category u users g group o others a - all

Operation + assign - remove = assign absolutely Permission r read w write x- execute Examples: $ chmod u-wx student removes wri:te and execute permission for users $ chmod u+rw, g+rw student assigns read and write permission for users and groups $ chmod g=rwx student assigns absolute permission for groups of all read, write and execute permissions RESULT: Thus the file manipulating commands were executed successfully. 3. DISPLAY COMMANDS date used to check the date and time syn: $ date EX: $ date Fri Feb 10 05:11:28 IST 2012 cal used to display the calendar syn: $ cal 2 2009 Ex: $ cal 2 2012 February 2012 Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 echo used to print the message on the screen. Syn: $ echo text Ex:$ echo "student" student ls used to list the files. Your files are kept in a directory. Syn: $ ls

Ex: $ ls 1 15 4 aaa d k oo s 10 16 5 aaaa dd kk ooo ss 100 17 6 aa.sh Desktop l p ssss 101 18 7 arun Documents ll Pictures Templates 102 19 77 a.sh Downloads m pp t.sh 11 2 8 b e meena prg.c ttt 111 20 88 bala eee meena.sh progm2 u 1114 21 888 bbb examples.desktop mm Public uu 114 22 9 bbbb g Music q Videos 12 222 99 bbbbb gaya mylist qq x 123 23 999 c h nimmi r y 13 3 9999 ccc hari nn ram yy 14 33 a channu h.c nnnn riya z 143 333 aa charan j o rrr zzz lp used to take printouts syn: $ lp filename man used to provide manual help on every UNIX commands. Syn: $ man unixcommand $ man cat who & who am i it displays data about all users who have logged in to the system currently. The next command displays about current user only. Syn: $ who $ who am i Ex: $ who nirmala tty7 2012-02-10 04:28 (:0) nirmala pts/0 2012-02-10 05:40 (:0) nirmala@nirmala-Inspiron-1440:~$ who am i nirmala pts/0 2012-02-10 05:40 (:0) uptime tells you how long the computer has been running since its last reboot or power-off. Syn: $ uptime Ex: $ uptime 05:42:29 up 1:14, 2 users, load average: 0.00, 0.01, 0.05 uname it displays the system information such as hardware platform, system name and processor, OS type. Syn: $ uname a

Ex: $ uname -a Linux nirmala-Inspiron-1440 2.6.38-8-generic #42-Ubuntu SMP Mon Apr 11 03:31:50 UTC 2011 i686 i686 i386 GNU/Linux Id - It is used to display the login name. Syntax : id Ex:$ id uid=1000(nirmala) gid=1000(nirmala) groups=1000(nirmala),4(adm),20(dialout),24(cdrom),46(plugdev),112(lpadmin),120(admin),122 (sambashare) Clear - It is used to clear the screen. Syntax : clear Example : $ clear bc stands for best calcualtor Ex:$ bc bc 1.06.95 Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc. This is free software with ABSOLUTELY NO WARRANTY. For details type `warranty'. 10+2 12 Quit hostname displays and set system host name syn: $ hostname Ex:$ hostname nirmala-Inspiron-1440 Tput - It is used to manipulate the screen. Syntax : tput < attributes > Example : $ tput rmso tty Used to know the terminal name that we are using Syntax - $tty Ex: $ tty /dev/pts/0 passwd password can be changed Syntax : $passwd Ex:$passwd pwd Will print your home directory on screen Syntax: pwd Ex:$ pwd

/home/nirmala exit terminates a process syn:$exit kill terminates or send a signal to process syn:$kill telnet connect to remote machine using the telnet protocol syn:$ telnet RESULT: Thus the display commands are executed successfully 4. GROUPING COMMANDS The semicolon (;) - used ot execute more than one command at a time eg: $ who ; date ; ls The && operator signifies the logical AND operation. It means that only if first command is successfully executed, then the nest command will be executed. Eg: $ ls who && date The || operator signifies the logical OR operation. It means the first command will happen to be unsuccessful, it will continue to execute next command. Eg:$ ls who || date RESULT: Thus the Grouping commands are executed successfully EX NO:3 STUDY OF VI EDITOR DATE: AIM: To introduce the concept of text editing vi editor and the options regarding the control of the editor. vi Editor A text editor is one of the most common and useful tools in all Operating Systems. Unix provides a versatile editor vi, a full-screen editor and owes its origin to Bill Joy. "vi" stands for visual editor. A vi session begins by invoking vi with or without a filename $vi $vi filename

The user is presented with a full empty screen, each line beginning with a ~. This is vi's way of indicating non-existent lines. Out of 25 lines on the terminal, 24 can be used to enter text. The last line is reserved for commands and also used by the system to display messages. vi functions in three modes namely: 1. Input modeWhere any key depressed is entered as text 2. Command modeWhere keys are used as commands to act on text (initial mode) 3. ex modeex mode commands that can be entered in the last line to act on text

INPUT M ODE vi starts with command mode. To insert text any of the following commands should be used.

Commands i I a

Function Inserts text to the left of the cursor. Inserts text at the beginning of line Appends text to right of cursor

A o O COMMAND MODE EDIT COMMANDS Command R

Appends text at end of line Opens line below Opens line above

Function Replaces more than a single character. The editor displays REPLACE in the last line. The existing text is overwritten as they are typed. Deletes a single character to the left and switches to Input mode. Deletes the character in the current cursor position Locates the text in the file. If not found, the message "Pattern not found" appears. Use n to repeat the forward search and N for backward search. Reverses the last change made to the buffer. Cuts the entire line Cuts the entire word Cuts a line from cursor position to the end of the line Cuts from the cursor position to the start of the line Copies (yanks) the entire line Copies the entire word Pastes the text

s x ?text

U or u dd dw d$ d0 yy yw p NAVIGATION COMMANDS Command b w | $ k j

Function Moves back to beginning of a word Moves forward to beginning of word Moves to start of the line Moves to end of the line Up one line Down one line

h l Ctrl+f Ctrl+b lG

Left one character Right one character Scrolls a page forward Scrolls a page backward To move to the specific line

One of the most notable features of vi is the facility of prefixing a number to most commands. When prefixed, commands interpret the instruction to be repeated as many times. For example 3x deletes the next three character. THE EX MODE The essential save and exit commands form the features of ex mode. Press : (colon) in command mode to switch to ex mode. The : is displayed in the last line. Type the command and press Enter key to execute the same. Command w Function Saves file, displays the number of lines & characters and returns to Input mode. If it is an unnamed file then vi puts a message. The file is saved under the given name Used to write specific line numbers to some file. The . (dot) represents current line, 0 for first line and $ could be used to represent last line. Quits vi session and returns to $ prompt. vi has a safety mechanism that warns if changes made to file are not saved. Quits vi session without saving any changes made since the last save Save and exit Escape to shell This is yet another powerful feature known as substitution. It is similar to Find and Replace. % represents all lines, g makes it global. To make vi ask for confirmation before replacing use gc instead of g. To insert another file into the current file. Splits screen into multiple windows and opens the file.

w file L1,L2 w file

q! wq sh %s/Sstr/Rstr/g

r file new file

~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Sample.txt [New File]

vi Editor for new file This is vi improved vim A rudimentary text ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Sample.txt 2L, 30C written vi Editor with Contents

RESULT: Thus the study of text manipulation using vi editor has been completed successfully.

EX NO:4 DATE: FAHRENHEIT TO CENTIGRADE CONVERSION AIM: To convert the Fahrenheit to centigrade ALGORITHM Step 1: Start Step 2: Read fahrenheit value Step 3: Convert fahrenheit to centigrade using the formulae: (fahrenheit 32) 5/9 Step 4: Print centigrade Step 5: Stop EX NO:5 DATE: ` FINDING THE AREA OF CIRCLE, SQUARE, RECTANGLE AND TRIANGLE AIM: To find the area of circle, square, rectangle and triangle using case statements. ALGORITHM: 1. Get two numbers from the user. 2. Select the option. 3. Execute the statement to find the area using case statements.. 4. Print the output EX. NO: 6 DATE: AIM:

nth POWER OF A GIVEN NUMBER

To compute the nth power of a given number ALGORITHM: 1. Get the value for the power & number to be computed. 2. Initialize the value for I as 2. 3. Set the variable ans as a. 4. Repeat the steps 5,6 until the value of I ie less than or equal to the power value. 5. Multiply the value of ans and a. 6. Increment the I value. 7. Display the value ans as result Ex No:7 DATE: SWAPPING VALUES OF TWO VARIABLES AIM: To Swap the values of two variables ALGORITHM Step 1 : Start

Step 2 : Read the values of a and b Step 3 : Interchange the values of a and b using another variable t as follows: Step 4 : t=a Step 5 : a=b Step 6: b=t Step 7: Print a and b Step 8: Stop EX NO:8 DATE MARK SHEET PREPERATION ALGORITHM: Step 1 : Start Step 2 : Read mark Step 3 : If mark > 90 then Print "S grade" Step 3.1 : else if mark > 80 then Print "A grade" Step 3.2 : else if mark > 70 then Print "B grade" Step 3.3 : else if mark > 60 then Print "C grade" Step 3.4 : else if mark > 55 then Print "D grade" Step 3.5 : else if mark Print "E grade" Step 3.6 : else Print "U grade" Step 4 : Stop Ex No:9 DATE: ODD OR EVEN AIM: To find the given number is Odd or Even ALGORITHM: Step 1: Start Step 2: Read number Step 3: If number divisible by 2 then Step 4: Print "Number is Even" Step 5: else Step 6: Print "Number is Odd" Step 7: Stop Ex No: 10 DATE: LEAP YEAR OR NOT AIM: To find the year is Leap year or not ALGORITHM:

Step 1: Start Step 2: Read the value of year Step 3: If year divisible by 400 then Step 4: Print "Leap year" Step 5: else if year divisible by 4 and not divisible by 100 then Step 6: Print "Leap year" Step 7: else Step 8: Print "Not a leap year" Step 9: Stop Ex No:11 DATE: BIGGEST OF 3 NUMBERS AIM: To find the biggest of three numbers ALGORITHM: Step 1: Start Step 2: Read values of a, b and c Step 3: If a > b and a > c then Step 4: Print "A is the biggest" Step 5: else if b > c then Step 6: Print "B is the biggest " Step 7: else Step 8: Print "C is the biggest" Step 9: Stop Ex No: 12 DATE: MULTIPLICATION TABLE AIM: To print the multiplication table ALGORITHM: Step 1: Start Step 2: Read the value of n Step 3: Initialize 1 to i Step 4: Print n, i, ni Step 5: Increment i by 1 Step 6: Repeat steps 4 and 5 until i<=10 Step 7: Stop Ex No: 13 DATE: SIMPLE CALCULATOR AIM: To perform arithmetic operations ALGORITHM: Step 1: Start Step 2: Read operands a and b Step 3: Display operation menu Step 4: Read option

Step 5: If option = 1 then Step 6: Calculate c = a + b Step 7: else if option = 2 then Step 8: Calculate c = a b Step 9: else if option = 3 then Step 10: Calculate c = a * b Step 11: else if option = 4 then Step 12: Calculate c = a / b Step 13: else if option = 5 then Step 14: Calculate c = a % b Step 15: else Step 16: Print "Invalid option" Step 17: Print c Step 18: Stop Ex No: 14 DATE: ARMSTRONG NUMBER AIM: To find the number is armstrong number or not ALGORITHM: Step 1: Start Step 2: Read number Step 3: Initialize 0 to sum and number to num Step 4: Extract lastdigit by computing number modulo 10 Step 5: Cube the lastdigit and add it to sum Step 6: Divide number by 10 Step 7: Repeat steps 46 until number > 0 Step 8: If sum = number then Step 9: Print Armstrong number Step 10: else Step 11: Print Not an Armstrong number Step 12: Stop Ex No: 15 DATE: PRIME NUMBER OR NOT AIM: To find the number is prime number or not ALGORITHM: Step 1: Start Step 2: Read the value of n Step 3: Initialize i to 2 Step 4: If n is divisible by i then Step 5: Print Not Prime and Stop Step 6: Increment i by 1 Step 7: Repeat steps 4 and 5 until i n/2 Step 8: Print "Prime"

Step 9: Stop EX NO 16 DATE: SUM OF 1..N NATURAL NUMBERS Algorithm Step 1 : Start Step 2 : Read n Step 3 : Initialize 0 to sum and 1 to i Step 4 : Add i to sum Step 5 : Increment i by 1 Step 6: Repeat steps 4-6 until i n Step 7 : Print sum Step 8 : Stop Ex No:17 DATE: FACTORIAL VALUE AIM: To find the factorial value of the given number ALGORITHM: Step 1: Start Step 2: Read number Step 3: Initialize 1 to fact and number to i Step 4: fact = fact * i Step 5: Decrement i by 1 Step 6: Repeat steps 46 until i > 0 Step 7: Print fact Step 8: Stop Ex No:18 DATE: NUMBER REVERSE AIM: To reverse the given number ALORITHM: Step 1: Start Step 2: Read number Step 3: Initialize 0 to reverse Step 4: Extract lastdigit by computing number modulo 10 Step 5: Compute reverse = reverse10 + lastdigit Step 6: Divide number by 10 Step 7: Repeat steps 46 until number > 0 Step 8: Print reverse Step 9: Stop Ex No: 19 DATE: FIBONACCI SERIES

AIM: To find the fibonacci series for the given number ALGORITHM: Step 1: Start Step 2: Read number of terms as n Step 3: Initialize 0 to f1, 1 to f2 and 2 to i Step 4: Print initial fibonacci terms f1, f2 Step 5: Generate next term using the formula f3 = f1 + f2 Step 6: Print f3 Step 7: Increment i by 1 Step 8: Assign f2 to f1 Step 9: Assign f3 to f2 Step 10: Repeat steps 59 until i n Step 11: Stop Ex No: 20 DATE: SUM OF THE DIGITS AIM: To find the sum of the digits of the given number ALGORITHM: Step 1: read the number Step 2: initialize sum to 0 Step 3: calculate sum modulo 10 Step 4: evaluate num divided to 10 Step 5: Repeat the step 3 &4 till num>0 Step 6: Print the sum Step 7: Stop Ex. No:21 DATE: REVERSING A STRING AIM: To write a shell program for Reversing A String ALGORITHM: 1. Enter the string. 2. Using wc-c command find the length of the string. 3. With the length find the reverse of the string. 2. Print the result. EX NO:22 DATE: VOWELS OR CONSONANTS Algorithm Step 1 : Start Step 2 : Read char Step 3 : If char is either 'a', 'e', 'i', 'o' or 'u' then Print "It's a vowel" Step 3.1 : else Print "It's a consonant" Step 4 : Stop

Ex. No: 23 DATE:

COMPARE TWO STRINGS

AIM: To write a Shell program for comparing two strings ALGORITHM: 1. Enter the two string using echo and read command. Using if and else compare the two string. Print the result. EX. No: 24 DATE: PALINDROME OR NOT AIM: To write a shell program for finding the given number is palindrome or not ALGORITHM: Step 1: Read the number a Step 2: inisialise d to a Step 3: c=0 b=1 Step 4: Evaluate b=a%10 c=c*10+b a=a/10 Step 5: repeat the step 4 till a>0 Step 6: if d=c Step 7: print it is palindrome Step 8: else print it is not a palindrome Step 9: stop ROOTS OF QUADRATIC EQUATION Ex. no :25 Date : AIM: To write a program to find the roots of the quadratic equation. EX. NO:26 DATE : COMPUTE XY USING FUNCTION AIM: To write a UNIX with C program to computes x raised to the power of y using function. ALGORITHM: Step 1: Start the program Step 2: Read the number x and y Step 3: Call the function power(x,y) Step 4: Calculate the factorial value using p=p*x else p=p/x Step 5: Print the power value f Step 6: Stop the program ASCENDING ORDER OF THE GIVEN NUMBER Ex.no : 27 Date :

AIM: To write a program to print the ascending and descending order of the given array ALGORITHM: STEP 1: Start the program STEP 2: Enter the size of the array STEP 3: Enter the elements of the array STEP 4: Set a loop up to the array size minus one STEP 5: Set a inner loop up to the size of the array STEP 6: Check whether the next array element is greater than or not STEP 7: If greater than exchange their position STEP 8: If not greater than then go to the loop STEP 9: After the execution of the inner loop the outer loop is executed STEP 10: Print the ascending order of the given array STEP 11: Print the descending order of the given array STEP 12: Stop. EX NO: 28 DATE: LINEAR SEARCH Aim: To search a element using Linear search ALGORITHM: Step 1: Start the program Step2: Enter the size of sorting Step 3: enter the element to be searched Step 4: If (k=a[i]) Step 5: Print the element in the position Step 6: else Print the element is not in the array Step 7: Stop SWAP TWO NUMBERS USING POINTERS AND FUNCTIONS Ex.no : 29 Date : AIM: To write a program to swap two number using pointer and functions ALGORITHM: Step-1 Start the program Step-2 Enter the two numbers Step-3 Call the display function Step-4 Pass the address of the two numbers of the Calling Step-5 Get the address in the Calling function in the pointer Step-6 swap the number using temporary variable Step-7 Print the swamped values in the main function Step-8 Stop ARRANGE NAMES IN ALPHABETICAL ORDER Ex.no : 30 Date : AIM:

To write a C program to arrange names in alphabetical order ALGORITHM: STEP 1: STEP 2: STEP 3: STEP 4: STEP 5: STEP 6: STEP 7: Start the program. Read input n. Get the names using for loop. Compare the names by using strcmp function. Print the names in alphabetical order. Stop the execution. MATRIX MULTIPLICATION

Ex.no : 31 Date : AIM: To write a C program to perform Matrix Multiplication. ALGORITHM: STEP 1: Start the program. STEP 2: Enter the row and column of the A matrix. STEP 3: Enter the row and column of the B matrix. STEP 4: Enter the elements of the A matrix. STEP 5: Enter the elements of the B matrix. STEP 6: Print the elements of the A matrix in matrix form. STEP 7: Print the elements of the B matrix in matrix form. STEP 8: Set a loop up to row. STEP 9: Set a inner loop up to column. STEP 10: Set another inner loop up to column. STEP 11: Multiply the A and B matrix and store the element in the C matrix. STEP 12: Print the resultant matrix. STEP 13: Stop the program EX NO: 32 DATE: MARK AGGREGATE Aim: To print the mark aggregate os students using dynamic memory allocation. Algorithm Step 1 : Read number of students, say n Step 2 : Request memory dynamically to store marks of n students using malloc and store the address in a Step 3 : If requested block of memory is not allocated then Stop Step 4 : Set up a loop and read array elements ai Step 5 : Initialize sum to 0 Step 6 : Set up a loop and array elements ai to sum Step 7 : Compute mark aggregate and display it

Step 8 : Release the requested memory Step 9 : Stop EX NO: 33 DATE: AIM: To print the dimentions of matrix using two dimentional array.

ALLOCATION FOR TWO DIMENSIONAL ARRAY

Algorithm Step 1 : Declare a pointer-to-pointer ptr variable Step 2 : Get number of rows and cols Step 3 : Request memory for ptr based on rows using calloc (Array of pointers) Step 4 : Set up a loop that iterates based on rows Step 4.1 : Request memory for each array element of ptr based on cols using calloc Step 5 : Set up a nested loop and display the 2D array with default values Step 6 : Release the requested memory and Stop EX. NO:34 DATE :

READ AND WRITE THE DATA IN THE FILE

AIM: To write a UNIX with C program to read and write the data in the file. ALGORITHM: Step 1: Start the program Step 2: Open the file using fopen(). Step 3: read the product name, code and price using scanf() function. Step 4: Write the input to the file Step 5: display the file contents using printf() function Step 6: close the file Step 8: Stop the program EX. NO:35 DATE : COPY THE CONTENTS OF ONE FILE INTO ANOTHER FILE AIM: To write a UNIX with C program to Copy the contents of one file into another file using file Handling. ALGORITHM: Step 1: Start the program Step 2: Open the file1 for reading using fopen(). Step 3: enter the text into the file1.

Step 4: open the file2 for writing Step 5: copy the contents of file1 into file2 Step 6: close the file1,file2 Step 8: Stop the program EX NO 36: DATE: APPENDING A RECORD TO THE FILE ALGORITHM: Step1 : Start the program Step 2: Open the file Employ.DAT Step 3: Enter the name,rno and basicpay Step4: Affer creating it should by appended with additional data Step 5: Stop the program RESULT: Thus the program is executed successfully.

You might also like