Вы находитесь на странице: 1из 53

COMPUTER PRACTICES LABORATORY I

DOCUMENT CREATION, TEXT MANIPULATION WITH SCIENTIFIC NOTATIONS

Aim: To open a new open office document and perform the following operations in it. 1. Text Alignment 2. Change line spacing to 1.5 3. Place a box to the entire text 4. Add the bullets and numbering 5. Change type of font types and sizes 6. Insert the symbols Algorithm: 1. To open OpenOffice writer use , Start > All Programs > OpenOffice.org 3.2 > OpenOffice.org Writer. 2. On the Menu Bar click, File > New > Text Document now a text document appears on your screen with name at the top of the screen. 3. Enter some text in it and select the text and make it as justified text by clicking Align Left icon in the tool bar or ctrl+L. 4. Enter some text in it and select the text and make it as justified text by clicking Align Right icon in the tool bar or ctrl+R. 5. Enter some text in it and select the text and make it as justified text by clicking Align Center icon in the tool bar or ctrl+E. 6. Enter some text in it and select the text and make it as justified text by clicking Align Justification icon in the tool bar or ctrl+J. 7. Make a line spacing between the lines as 1.2 using Format > Paragraph > Indent & Spacing then select line spacing as fixed and change it to 1.5

Computer Science & Engineering

Page 1

COMPUTER PRACTICES LABORATORY I


8. To insert a box to a text select the box from drawing tool by , ToolBar -> Drawing 9. Makes the text as bullets and numbering by Format > Bullets and Numbering. 10. Change the style and size of the text by using the options in the tool bar or use Format > Character. 11. Insert special characters by Insert > Special Characters.

Output: 1. Text Alignment LEFT A computer is a programmable machine that receives input, stores and manipulates data/information, and provides output in a useful format. RIGHT Input: Information and programs are entered into the computer through Input devices such as the keyboard, disks, or through other computers via network connections or modems connected to the Internet. The input device also retrieves information off disks. CENTER Output: Output Devices displays information on the screen (monitor) or the printer and sends information to other computers. They also display messages about what errors may have occurred and brings up message or dialog box asking for more information to be input. The output device also saves information on the disk for future use. JUSTIFY Processing: The CPU or central processing unit is sometimes called the Control Unit and directs the operation of the input and output devices. The Coprocessor or the ArithmeticLogic Unit does arithmetic and comparisons. The memory or RAM temporarily stores information (files and programs) while you are using or working on them. The BIOS or basic input/output system controls the dialogue between the various devices.

2. Change line spacing to 1.5 Line Spacing - 1.0 The CPU or central processing unit is sometimes called the Control Unit and directs the operation of the input and output devices. The Coprocessor or the Arithmetic-Logic Unit does arithmetic and comparisons. The memory or RAM temporarily stores information
Computer Science & Engineering Page 2

COMPUTER PRACTICES LABORATORY I


(files and programs) while you are using or working on them. The BIOS or basic input/output system controls the dialogue between the various devices. Line Spacing 1.5 The CPU or central processing unit is sometimes called the Control Unit and directs the operation of the input and output devices. The Coprocessor or the Arithmetic-Logic Unit does arithmetic and comparisons. The memory or RAM temporarily stores information (files and programs) while you are using or working on them. The BIOS or basic input/output system controls the dialogue between the various devices.

3. Placing a box to the entire text

UNITED INSTITUTE OF TECHNOLOGY

4. Adding bullets and numbering Bullets Keyboard Mouse Numbering 1. Printer 2. Monitor

5. Changing type of font types and sizes Times New Roman Verdana Book Antiqua Arial black
8

10

12

14

6. Inserting the symbols Pie - Summation -


Computer Science & Engineering Page 3

COMPUTER PRACTICES LABORATORY I

7. Superscript and Subscript (A+B)2 = A2+ B2 + 2AB Ca(HCO3)2 -> CaCO3 + Co2 + H2O

8. Inserting Equations

Result: Thus the required operations in the word document have been made and the output has been obtained.

Computer Science & Engineering

Page 4

COMPUTER PRACTICES LABORATORY I ADVERTISEMENT


Aim: To prepare an advertisement to a company with the following specifications i. ii. iii. Attractive Page Border. Design the name of company using WordArt. Use ClipArt

Using of OpenOffice writer. Algorithm: 1. To open OpenOffice writer use , Start > All Programs > OpenOffice.org 3.2 > OpenOffice.org Writer. 2. On the Menu Bar click, File > New > Text Document now a text document appears on your screen with name at the top of the screen. 3. Save file use File > Save As> give valid name and click Save. 4. Select the Page Border use Format > Page > Borders then select your style of Page Border. 5. Design the company name use View > Toolbars > FontWork Enable FontWork Option and Design Company Name. 6. Insert ClipArt use Insert > Pictures select the picture and insert.

Computer Science & Engineering

Page 5

COMPUTER PRACTICES LABORATORY I

Output:

Result: Thus the above Advertisement to a company has been designed and the output has been obtained.
Computer Science & Engineering Page 6

COMPUTER PRACTICES LABORATORY I VISITING CARD


Aim: To design a Visiting Card for a company following specification i. ii. Size of the Visiting Card 4 X 3. Name of the company with a WortArt.

Using of OpenOffice writer. Algorithm: 1. To open OpenOffice writer use , Start > All Programs > OpenOffice.org 3.2 > OpenOffice.org Writer. 2. On the Menu Bar click, File > New > Text Document now a text document appears on your screen with name at the top of the screen. 3. Save file use File > Save As> give valid name and click Save. 4. Size of Visiting Card use Format > Page > Page > then change the Width and height 5. Design the company name use View > Toolbars > FontWork Enable FontWork Option and Design Company Name

OUTPUT:

Result: Thus the above Visiting Card to a company has been designed and the output has been obtained.

Computer Science & Engineering

Page 7

COMPUTER PRACTICES LABORATORY I LETTER HEAD


Aim: To Create a Letter Head for UIT College Using of OpenOffice writer. Algorithm: 1. To open OpenOffice writer use , Start > All Programs > OpenOffice.org 3.2 > OpenOffice.org Writer. 2. On the Menu Bar click, File > New > Text Document now a text document appears on your screen with name at the top of the screen. 3. Save file use File > Save As> give valid name and click Save. 4. Size of Visiting Card use Format > Page > Header > then Enable Header On option 5. Size of Visiting Card use Format > Page > Footer > then Enable Footder On option

Computer Science & Engineering

Page 8

COMPUTER PRACTICES LABORATORY I


OUTPUT:

Result: Thus the above Letter Head for UIT College has been designed and the output has been obtained.

Computer Science & Engineering

Page 9

COMPUTER PRACTICES LABORATORY I SCIENTIFIC NOTATION AND FORMULA


Aim: To create Scientific Notation and Formula using OpenOffice.org. Algorithm: 1. To open OpenOffice writer use , Start > All Programs > OpenOffice.org 3.2 > OpenOffice.org Writer. 2. On the Menu Bar click, File > New > Text Document now a text document appears on your screen with name at the top of the screen. 3. Save file use File > Save As> give valid name and click Save. 4. Scientific Notation use Format > Character > Position then Enable Superscript and Subscript options 5. Insert Formula use Insert > Object > formula then Enter your Formula Output: Scientific Notation: (A+B)2 = A2+ B2 + 2AB Ca(HCO3)2 -> CaCO3 + Co2 + H2O Formula:

Result: Thus the above Scientific Notation and Formula created and the output has been obtained.

Computer Science & Engineering

Page 10

COMPUTER PRACTICES LABORATORY I


TABLE CREATION, TABLE FORMATTING AND CONVERSION

Aim: To perform Table Creation, Formatting and Conversion using OpenOffice.org . Algorithm: 1. To open Open Office writer use , Start > All Programs > OpenOffice.org 3.2 > OpenOffice.org Writer. 2. On the Menu Bar click, File > New > Text Document now a text document appears on your screen with name at the top of the screen. 3. To insert a new table, position the cursor where you want the table to appear, then use any of the following methods to open the Insert Table dialog box:

From the main menu, select Table > Insert > Table. Press Ctrl+F12. From the Standard toolbar, click the Table icon

4. Under Size, change the no of columns and rows based on the document. 5. In the Options space, Heading defines the first row(s) in the table as headings Repeat heading repeats the heading row(s) of the table at the top of subsequent pages if the table spans more than one page. Dont split table prevents the table from spanning more than one page. Border surrounds each cell of the table with a border. This border can be modified or deleted later. The AutoFormat button opens a dialog from where it is possible to select one of the many predefined table layouts.

6. Click OK to create the table of your choice. 7. To insert rows in the table later, Use tab key to add rows in the last column.
Page 11

Computer Science & Engineering

COMPUTER PRACTICES LABORATORY I


Click Table > Insert > Rows or click the Insert Rows icon Right click select Row > insert .

8. To insert columns in the table later, Click the second column, Table > Insert > Columns or click the Insert Column icon.

Right click select Column > insert.

9. To delete rows and columns, Click in one of the empty rows you just added, click Table > Delete > Rows or click the Delete Row icon(The row is deleted.).

Click in the empty column you just added, click Table > Delete > Columns or click the Delete Column column is deleted.). icon on the Table Toolbar(The middle

10. For Table Conversion, Select the text and click Table > Convert > Text to Table > Paragraph. Under Separate text at, select Tabs or Semicolon or Other to determine what will be used to divide the data into different cells. To convert table into text, click in the table then click Table to Text > Paragraph. Table > Convert >

11. To Delete Table, Click the table you want to delete. Click Table > Delete > Table.

Computer Science & Engineering

Page 12

COMPUTER PRACTICES LABORATORY I


Output:

Table To Text Conversion

Roll_No;Name 101;Senthil kumar K 102;Raj Kumar P 103;Sathish B Text To Table Conversion Name Roll_No 101 102 103 Senthil kumar K Raj Kumar P Sathish B

Result: Thus the operations on the table have been performed and the required output has been obtained using OpenOffice.org

Computer Science & Engineering

Page 13

COMPUTER PRACTICES LABORATORY I


MAIL MERGE AND LETTER PREPARATION

Aim: To perform mail merge and letter preparation using OpenOffice.org. Algorithm: 1. To open Open Office writer use , Start > All Programs > OpenOffice.org 3.2 > OpenOffice.org Writer. 2. On the Menu Bar click, File > New > Text Document. 3. Click Tools > Mail Merge Wizard, the Mail Merge Wizard window will appear. 4. Under select starting document select create a new document then click next. 5. Select document type as letter, then click next. 6. In the address list click OK then click next. 7. In the create salutation space check this document should contain a salutation then click next. 8. In the adjust layout space, we can adjust the alignment and salutation position and click next. 9. Edit document space, click edit document if needed click next. 10. Personalize document, we can edit individual document. 11. Save the document by clicking save starting document button and enter the document name, click OK. 12. Click Finish.

Computer Science & Engineering

Page 14

COMPUTER PRACTICES LABORATORY I

Output: From M.Anantha Krishnan BE CSE A I YEAR United Institute of Technology Coimbatore-20.

To Mr.N.K.Madhavan No.15,IT Quarters, Coimbatore - 641044 India

Respected Sir/Madam, SUBJECT: Regarding a symposium on Internet. I take great privilege to welcome you for the symposium which is to be conducted in our college. The symposium is about the various advancements in internet.Mr.Bill Gates ,chairman of Microsoft Corporation has accepted to deliver a guest lecture on 27th of September 2008.The program commences by 10.00 am and ends by 12.30 pm.Kindly grace this occasion with your august presence. Thanking you. Yours Sincerely M.Ananthakrishnan

Result: Thus the mail merge operation have been performed and the required output has been obtained.

DRAWING FLOW CHART


Computer Science & Engineering Page 15

COMPUTER PRACTICES LABORATORY I

Aim:
To draw a flow chart for a given problem in the OpenOffice.org.

Algorithm:
1. Open a new open office document. 2. Open drawing toolbar by clicking View > Toolbars > Drawing. 3. Draw a flow chart for the given problem by using the drawing tool bar.

Output:

Result:
Thus the flow chart has been drawn for the greatest of three numbers problem and the required output has been obtained.

Computer Science & Engineering

Page 16

COMPUTER PRACTICES LABORATORY I


CHART LINE, XY, BAR AND PIE

Aim:
To Draw a line, XY, bar and pie chart for a given user data in OpenOffice.org Calc .

Algorithm:
1. Click Start > Programs > OpenOffice.rg > OpenOffice.org calc. 2. Enter the data. 3. Select the data to be manipulated. 4. Click Insert > Chart then select Line to display line chart. 5. Do the above steps for XY, Bar and Pie charts.

Output:

Result:
Thus the required operation is performed and the required output is obtained.

Computer Science & Engineering

Page 17

COMPUTER PRACTICES LABORATORY I


FORMULA FORMULA EDITOR

Aim: To perform the formula editor in OpenOffice.org Calc . Algorithm: 1. Click Start > Programs > OpenOffice.rg > OpenOffice.org calc. 2. Enter the data. 3. Click View > Formula Bar. 4. Perform the required operations in the formula editor. 5. Display the output.

Output: S.NO 1 2 3 4 5 STU NAME KRISHNA SANTHOSH MURALI VINOD HARI PHY CHE MAT COMP ENG TOTAL PERCENTAGE 90 92 95 98 95 470 94 90 85 86 81 85 427 85.4 90 95 96 88 99 468 93.6 85 86 75 95 96 437 87.4 90 95 96 98 90 469 93.8

S.NO 1 2 3 4 5

EMP NAME KRISHNAN RAHUL RATAN MURLI CLIFF

BASIC PAY HRA PF DA TA TOTAL 35000 10000 500 3500 1000 49000 20000 9000 255 1500 1000 31245 30000 8000 650 2500 1000 40850 12000 10500 800 3600 1000 26300 17000 9500 940 2500 1000 29060

Result: Thus the formula-editor operation is performed and the required output is obtained using OpenOffice.org Calc.

Computer Science & Engineering

Page 18

COMPUTER PRACTICES LABORATORY I


SPREADSHEET INCLUSION OF OBJECT, PICTURE AND GRAPHICS, PROTECTING THE DOCUMENT

Aim: To perform the insertion of objects, graphics and protecting the document in OpenOffice.org Calc. Algorithm: 1. Click Start > Programs > OpenOffice.rg > OpenOffice.org calc. 2. Enter the data. 3. Perform the insertion of objects using Insert > Object. 4. Click Insert > Picture to add pictures and graphics. 5. Select Tools > Protect Document > Document to protect the structure of the document 6. Select Tools > Protect Document Sheet to protect sheets from changes . 7. Use Tools > Protect Document then deselect sheet or document to unprotect sheet or document. 8. Display the output.

Computer Science & Engineering

Page 19

COMPUTER PRACTICES LABORATORY I

Output:

Result: Thus the required operations are performed and the required output is obtained using OpenOffice.org Calc.

SORTING AND IMPORT/EXPORT FEATURES


Computer Science & Engineering Page 20

COMPUTER PRACTICES LABORATORY I

Aim: To perform the sorting and import/export features in OpenOffice.org Calc. Algorithm: 1. Click Start > Programs > OpenOffice.org > OpenOffice.org calc. 2. Enter the data. 3. Select the column or row then click Data > Sort. 4. Display the output for Sorting. 5. Click Start > Run. 6. Type Notepad and click OK. 7. Enter the contents as shown below: a. "Sales Per Region"," Africa"," Asia"," Europe, Total" b. "Jan",34,67,56,157 c. "Feb",36,87,78,201 d. "Mar",34,67,56,157 e. "Apr",36,87,78,201 f. "May",34,67,56,157 g. "Jun",36,87,78,201 h. "Total",210,462,402, 8. Click File > Save and Enter the Name as Import.csv and Click Save. 9. Click Start > Programs > OpenOffice.org > OpenOffice.org calc. 10. Click File > Open and select the Import.csv file and Click Open. 11. The contents typed in Notepad will be available in Calc. 12. Click Start > Programs > OpenOffice.org > OpenOffice.org calc. 13. Enter the data similar to import contents in the Open Office Calc. 14. Choose File > Save as. You will see the Save as dialog. 15. In the File type field select the format "Text CSV". 16. Enter a Name as Export and Click Save. 17. The contents typed in Calc will be exported. 18. Verify the Exported contents by opening the file with Notepad.

Computer Science & Engineering

Page 21

COMPUTER PRACTICES LABORATORY I


Output:

Computer Science & Engineering

Page 22

COMPUTER PRACTICES LABORATORY I

Export.csv Notepad File "Sales Per Region"," Africa"," Asia"," Europe","Total" "Jan",34,67,56,157 "Feb",36,87,78,201 "Mar",34,67,56,157 "Apr",36,87,78,201 "May",34,67,56,157 "Jun",36,87,78,201 "Total",210,462,402,

Result: Thus the required operations are performed and the required output is obtained using OpenOffice.org Calc.

GREATEST AMONG THREE NUMBERS

Computer Science & Engineering

Page 23

COMPUTER PRACTICES LABORATORY I


Aim: To write a c program to find a greatest number among three numbers . Algorithm: 1. open a new file 2. Get the three numbers from the user as input. 3. Find the greatest number form those three number. 4. Pint the greatest number. Coding: #include<stdio.h> #include<conio.h> Void main() { Int a,b,c; Printf(Enter the value of A); Scanf(%d,&a); Printf(Enter the value of B) Scanf(%d,&b); Printf(Enter the value of C); Scanf(%d,&c); If(a>b && a>c) Printf(A is greater); Else if (b>a && b>c) Printf(B is greater); Else if (c>a && c>b) Printf(C is greater); }

Flowchart:
Computer Science & Engineering Page 24

COMPUTER PRACTICES LABORATORY I

Output:
Enter the value of A:10 Enter the value of B:20 Enter the value of C:30

C is greater.

Result:
Thus the C program for Greatest of three numbers has been executed and the required output has been obtained.

Computer Science & Engineering

Page 25

COMPUTER PRACTICES LABORATORY I


ARITHMETIC OPERATIONS

Aim: To write a C program to perform a Arithmetic operations(+,-,*,/) Algorithm: 1. Open a new file 2. Get the two numbers as input and operation to perform from the user 3. Perform the arithmetic operation as per the users input by using CASE 4. print the result

Flowchart:
Start Read a,b and ch

is ch

Case 1

c=a+b

Print c

Case 2

c=a-b

Print c

Case 3

c=a*b

Print c

Case 4

c=a/b

Print c

A Stop

Coding:
Computer Science & Engineering Page 26

COMPUTER PRACTICES LABORATORY I


#include<stdio.h> #include<conio.h> void main() { int a,b,c,ch; clrscr(); printf("Enter the value of A"); scanf("%d",&a); printf("Enter the valur of B"); scanf("%d",&b); printf("1.addition\n2.subtraction\n3.multiplication\ndivision"); printf("Enter your choice"); scanf("%d",&ch); do switch(ch) { case 1: c=a+b; printf("%d",c); break; case 2: c=a-b; printf("%d",c); break; case 3: c=a*b; printf("%d",c); break; case 4: c=a/b; printf("%d",c); break; }
Computer Science & Engineering Page 27

COMPUTER PRACTICES LABORATORY I


while(ch>4); getch(); }

Output:
Enter the value of A:12 Enter the valur of B:12 1.addition 2.subtraction 3.multiplication 4.Division Enter your choice1 24

Result:
Thus the C program for Arithmetic operations have been executed and the required output has been obtained.

PASCALS TRIANGLE
Computer Science & Engineering Page 28

COMPUTER PRACTICES LABORATORY I

Aim: To write a C program to print the Pascals triangle. Algorithm: 1. Start. 2. Get the number of lines to print from the user. 3. Generate the triangle by using conditional loops. 4. Print the triangle. 5. Stop.

Flowchart:

Start

Stop

Computer Science & Engineering

Page 29

COMPUTER PRACTICES LABORATORY I


Coding:

#include<stdio.h> #include<conio.h> void main() { int n=1,c=1,i,r,a=1,b=0; clrscr(); printf("\t\t\tPASCAL's TRIANGLE"); printf("\n\nEnter the number of rows to print:"); scanf("%d",&r); printf("\n\n"); while(n<=r) { while(a<r) { printf(" "); a=a+1; } for(i=n;i<=c;i++) printf(" %d",i); for(i=c-1;i>=n;i--) printf(" %d",i); printf("\n"); c=c+2; n=n+1; b=b+1; a=b+1; } getch(); }

Computer Science & Engineering

Page 30

COMPUTER PRACTICES LABORATORY I


Output:

PASCAL's TRIANGLE

Enter the number of rows to print:5

1 2 3 2 3 4 5 4 3 4 5 6 7 6 5 4 5 6 7 8 9 8 7 6 5

Result: Thus the C program for pascals triangle has been executed and the required output has been obtained. FIBONACCI SERIES
Computer Science & Engineering Page 31

COMPUTER PRACTICES LABORATORY I

Aim: Write a C program to printa Fibonacci series for a limit. Algorithm: 1. Open a new file. 2. Get the limit or length of the series from the user. 3. find the elements of the series 4. Print the elements

Flowchart: Start

Read n

Assign f1=-1,f2=1,f3=0

for ( i=0 ; i<n ;i++)

No

c= a+b

Yes Print c

a=b b=c

Stop

Coding: #include<stdio.h>
Computer Science & Engineering Page 32

COMPUTER PRACTICES LABORATORY I


#include<conio.h> main() { int f1=-1,f2=1,f3,n,i; clrscr(); printf("Enter the limit :"); scanf("%d",&n); if(n<3) { printf("0"); printf("\n1"); } else { for(i=1;i<=n;i++) { f3=f1+f2; f1=f2; f2=f3; printf("\n%d",f3); } } getch(); }

Output:

Enter the limit: 7 The series is.


0 1 1 2 3 5 8

Result: Thus the program for Fibonacci series is executed and the required output is obtained. SWITCH CASE

Computer Science & Engineering

Page 33

COMPUTER PRACTICES LABORATORY I

Aim: To write a C program to perform the operations below: Algorithm: 1. Open a new file 2. Get the number from the user. 3. Gets the choice of operation from the user as input using CASE. 4. Perform the appropriate operation on the given number. 5. Print the result. Prime or not. Reverse of the number. Fibonacci Series for the limit.

Flowchart:

C A B

A Computer Science & Engineering B Page 34

COMPUTER PRACTICES LABORATORY I

STOP

Coding: #include<stdio.h> #include<conio.h> void main() { int f1=-1,f2=1,f3,n,ch,i; clrscr(); printf("Enter the value of n: "); scanf("%d",&n); printf(1.Prime or Not\n2.Reverse of the number\n3.Fibonacci Series\n4.Exit); q:printf("Enter your choice"); scanf("%d",&ch); switch(ch) { case 1:
Computer Science & Engineering Page 35

COMPUTER PRACTICES LABORATORY I


if(n<2) printf("the no is prime"); else { for(i=2;i<n;i++) { if(n%i==0) f=1; break; } if(f==0) printf("the no is prime"); else printf("the no is not prime"); } break; case 2: while(n>0) { a=n%10; n=n/10; printf("%d",a); } break; case 3: if(n<3) { printf("0"); printf("\n1"); } else { for(i=1;i<=n;i++) { f3=f1+f2; f1=f2; f2=f3; printf("\n%d",f3); } } break;

case 4:
Computer Science & Engineering Page 36

COMPUTER PRACTICES LABORATORY I


exit(0); default: printf(Enter the Correct Choice:); goto q; } getch(); }

Output: Enter the value of n: 13 Enter your choice: 1 The no is prime.

Result: Thus the program is executed to perform the above operations and the output is verified successfully. SEARCHING AN ELEMENT IN AN ARRAY
Computer Science & Engineering Page 37

COMPUTER PRACTICES LABORATORY I

Aim: To write a C program to search a element in a array. Algorithm: 1. To open a new file. 2. Get a n number of elements from the user and store it in a array 3. Get a element to be searched in the array form the user 4. Search a that particular element in the array by using the for loop. 5. print the result. Flowchart:

START

READ n, a[]

STOP

Coding:
Computer Science & Engineering Page 38

COMPUTER PRACTICES LABORATORY I


#include<stdio.h> #include<conio.h> main() { int a[15],n,e,i,f=0; clrscr(); printf("Enter the number of elements :"); scanf("%d",&n); printf("Enter the elements....."); for(i=0;i<n;i++) scanf("%d",&a[i]); printf("Enter the element to search :"); scanf("%d",&e); for(i=0;i<n;i++) { if(e==a[i]) f=1; } if(f==1) printf("%d is found",e); else printf("%d is not found",e); getch(); }

Output:
Enter the size of the array: 6 Enter the elements. 1 2 3 4 5 6 Enter the element to search: 6 6 is available in the array

Result:
Thus the program for searching a element in the array is executed and the required output is obtained.

Computer Science & Engineering

Page 39

COMPUTER PRACTICES LABORATORY I


MATRIX ADDITION

Aim: To write a C program to perform matrix addtition. Algorithm: 1. To open a new file. 2. Initialize the matrix 3. Get the input matrix from the user 4. Perform the matrix addition 5. Print the output.

Flowchart: FLOWCHART FOR MATRIX ADDITION start Read row, col for(i=0;i<row;i++)

for(j=0;j<col;j++)

Read a[i][j]
A

for(i=0;i<row;i++)

Computer Science & Engineering

Page 40

COMPUTER PRACTICES LABORATORY I

for(i=0;i<row; i++) for(j=0;j<col;j ++) c[i][j]= ai][j]+b[i][j]

for(i=0;i<row;i ++) for(j=0;j<col; j++) Print c[i][j]

Stop

Coding:
Computer Science & Engineering Page 41

COMPUTER PRACTICES LABORATORY I


#include<stdio.h> #include<conio.h> main() { int a[3][3],b[3][3],c[3][3]; int i,j; clrscr(); printf("Enter the elements of matrix A..."); for(i=1;i<=3;i++) { for(j=1;j<=3;j++) { scanf("%d",&a[i][j]); } } printf("Enter the elements of matrix B..."); for(i=1;i<=3;i++) { for(j=1;j<=3;j++) { scanf("%d",&b[i][j]); } } for(i=1;i<=3;i++) { for(j=1;j<=3;j++) { c[i][j]=a[i][j]+b[i][j]; } } printf("The result is........."); for(i=1;i<=3;i++) { for(j=1;j<=3;j++) { printf("\n%d",c[i][j]); } } getch(); }

Computer Science & Engineering

Page 42

COMPUTER PRACTICES LABORATORY I


Output: Enter the matrix A: 1 2 1 2 1 2 Enter the matrix B: 1 2 1 2 1 2

3 3 3

3 3 3

The resultant matrix is.. 2 4 6 2 4 6 2 4 6

Result: Thus the program for matrix addition is performed and the required output is obtained.

STRING CONCATENATION

Computer Science & Engineering

Page 43

COMPUTER PRACTICES LABORATORY I


Aim: To write a C program to perform a string concatenation. Algorithm: 1. To open a new file. 2. Get a two strings from the user. 3. To find the length of the string by using strlen() function. 4. To concatenate that strings 5. Print the output. Flowchart:

Coding:

Computer Science & Engineering

Page 44

COMPUTER PRACTICES LABORATORY I


#include<stdio.h> #include<conio.h> #include<string.h> void main() { int a,b,c; char i,j; char s1[10],s2[10],s3[10]; clrscr(); printf("Enter the first string :"); scanf("%s",s1); printf("Enter the second string :"); scanf("%s",s2); a=strlen(s1); b=a+strlen(s2); for(i=0;i<a;i++) s3[i]=s1[i]; for(i=a;i<=b;i++) s3[i]=s2[i-a]; printf("\n\nAfter the concatenation:"); printf("%s",s3); getch(); }

Output: Enter the first string UNITED INSTITUE Enter the second string OF TECHNOLOGY Then the resultant string is.. UNITED INSTITUE OF TECHNOLOGY

Result: Thus the program for string concatenation is performed and the required output is obtained. STRUCTURES
Computer Science & Engineering Page 45

COMPUTER PRACTICES LABORATORY I

Aim: To write a C program to display the student information by using structures. Algorithm: 1. 2. 3. 4. 5. Flowchart: To open a new file. Get a student information from the user. To get the input query from the user Based on the users query reterive the information. Print the output. start

struct student roll no: integer name[30]: character mark 1, mark 2 mark 3, : integer Read n for(i=0;i<=n;i++)

read stu[i].rollno, stu[i].name, stu[i].mark1, stu[i].mark2, stu[i].mark3

for(i=0;i<=n;i++)

Print stu[i].rollno, stu[i].name, stu[i].mark1, stu[i].mark2, stu[i].mark3

stop

Computer Science & Engineering

Page 46

COMPUTER PRACTICES LABORATORY I


Coding: #include<stdio.h> #include<conio.h> void main() { struct student { int rollno; char name[10]; int mark1; int mark2; int mark3; }stu[35]; int n,i; clrscr(); printf("Enter the number of student :"); scanf("%d",&n); printf("\n\nEnter the student's roll no, name and marks..."); for(i=1;i<=n;i++) { printf("\nRoll no:"); scanf("%d",&stu[i].rollno); printf("Name:"); scanf("%s",stu[i].name); printf("Mark1:"); scanf("%d",&stu[i].mark1); printf("Mark2:"); scanf("%d",&stu[i].mark2); printf("Mark3:"); scanf("%d",&stu[i].mark3); } printf("\n\t\tStudent details"); printf("\nROLL_NO\tNAME\tTOTAL\tAVG"); for(i=1;i<=n;i++) { printf("\n%d",stu[i].rollno); printf("\t%s",stu[i].name); printf("\t%d",(stu[i].mark1+stu[i].mark2+stu[i].mark3)); printf("\t%d",((stu[i].mark1+stu[i].mark2+stu[i].mark3)/3)); } getch(); }

Output:
Computer Science & Engineering Page 47

COMPUTER PRACTICES LABORATORY I


Enter the number of student : 2 Enter the student's roll no, name and marks...

Roll no: 101 Name: Rajesh K Mark1 : 85 Mark2 : 90 Mark3 : 95 Roll no: 102 Name: Vimal L Mark1 : 80 Mark2 : 85 Mark3 : 75

Student Details ROLL_NO NAME 101 102 Rajesh K Vimal L

TOTAL 270 240

AVG 90 80

Result: Thus the program for student information using structures is performed and the required output is obtained.

RECURSIVE FUNCTION
Computer Science & Engineering Page 48

COMPUTER PRACTICES LABORATORY I

Aim: To write a C program to Perform a Factorial operation using recursive function.

Algorithm:
1. 2. 3. 4. Flowchart: Open a new file. Get a value from the user to find factorial. Perform the operation Print the output.

Computer Science & Engineering

Page 49

COMPUTER PRACTICES LABORATORY I


Coding: #include<stdio.h> #include<conio.h> main() { int n,f; clrscr(); printf("Enter the number :"); scanf("%d",&n); if(n==0) printf("factorial of 0 is 1"); else { f=fact(n); printf("factorial of %d is :%d",n,f); } getch(); } fact(int a) { int f=1,i; for(i=1;i<=a;i++) f=i*fact(a-1); return f; }

Output: Enter the number:5 Factorial of the given number is:120

Result: Thus the program for Factorial using recursive function is performed and the required output is obtained WORKING WITH FILES
Computer Science & Engineering Page 50

COMPUTER PRACTICES LABORATORY I

Aim: To write a program to perform read and write operations using files. Algorithm: 1. Open a new file. 2. Enter the data in to the file. 3. Read t data from file. 4. Display the text. 5. Close the file.

Flowchart:

Coding:
Computer Science & Engineering Page 51

COMPUTER PRACTICES LABORATORY I


#include <stdio.h> #include<conio.h> main() { FILE *fs, *ft ; char ch ; char file1[30],file2[30]; fs = fopen ( pr1.c, r ) ; if ( fs == NULL ) { puts ( Cannot open source file ) ; exit( ) ; } printf(\nData from the file is read\nPress Anykey to Write..\n); ft = fopen ( pr2.c, w ) ; if ( ft == NULL ) { puts ( Cannot open target file ) ; fclose ( fs ) ; exit( ) ; } while ( 1 ) { ch = fgetc ( fs ) ; if ( ch == EOF ) break ; else fputc ( ch, ft ) ; } fclose ( fs ) ; fclose (t printf(\nData is written in to the file ); getch(); }

Computer Science & Engineering

Page 52

COMPUTER PRACTICES LABORATORY I

Output: Data from the file is read Press Any key to Write.. Data is written in to the file

Result: Thus the C program is executed to perform read and write operations in files and the output is obtained successfully.

Computer Science & Engineering

Page 53

Вам также может понравиться