cp lab 1 manual 2009-srit

71
SRI RAMAKRISHNA INSTITUTE OF TECHNOLOGY COIMBATORE-10 DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 080230002 - COMPUTER PRACTICE LABORATORY-I SEMESTER I 2009-2010

Upload: gowtama-krishna

Post on 22-Nov-2014

423 views

Category:

Documents


6 download

TRANSCRIPT

Page 1: Cp Lab 1 Manual 2009-Srit

SRI RAMAKRISHNA INSTITUTE OF TECHNOLOGY COIMBATORE-10

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

080230002 - COMPUTER PRACTICE LABORATORY-I

SEMESTER I

2009-2010

Page 2: Cp Lab 1 Manual 2009-Srit

Prepared by

Ms. Preethi Sheba Hepsiba Darius, Lecturer, CSE

Ms.K.Vidya, Lecturer, IT

Mr.T.C.Ezhil Selvan, Lecturer, IT

ii

Page 3: Cp Lab 1 Manual 2009-Srit

List of Experiments

a) WORD PROCESSING

1. Document creating, Text Manipulation with Scientific Notations.

2. Table creation, Table formatting and Conversion.

3. Mail Merge and Letter Preparation.

4. Drawing – Flow Chart.

b) SPREADSHEET

5. Chart – Line, XY, Bar and Pie.

6. Formula – Formula Editor.

7. Spread Sheet – inclusion of object, Picture and graphics, protecting the

document and sheet.

8. Sorting and Import / Export features.

SIMPLE C PROGRAMMING

9. Data types, Expression Evaluation, Condition Statements.

10. Arrays

11. Structures and Unions

12. Functions.

iii

Page 4: Cp Lab 1 Manual 2009-Srit

CONTENTS S.No Name of Experiment Page No.

List of Experiments iii

Table of Contents iv

WORD PROCESSING *

1

DOCUMENT CREATION, TEXT MANIPULATION WITH SCIENTIFIC NOTATIONS Lab 1 - Sample output

1

5

2 TABLE CREATION, TABLE FORMATTING AND CONVERSION Lab 2 – Sample output

6

8

3 MAIL MERGE AND LETTER PREPARATION Lab 3 – Sample output

9 11

4 DRAWING – FLOWCHART Lab 4 – Sample output

15 17

SPREADSHEET *

5 LINE, XY, BAR and PIE Lab 5 – Sample output

19 21

6 FORMULA EDITOR Lab 6 – Sample output

25 28

7 INCLUSION OF OBJECT, PICTURE AND GRAPHICS, PROTECTING THE DOCUMENT AND SHEET

31

8 SORTING AND IMPORT / EXPORT FEATURES Lab 8 – Sample output

33 35

iv

Page 5: Cp Lab 1 Manual 2009-Srit

C PROGRAMMING

9 DATA TYPES, EXPRESSION EVALUATION AND CONDITION STATEMENTS

A. AREA AND CIRCUMFERENCE OF CIRCLE B. FACTORIAL OF A GIVEN NUMBER C. GENERATING FIBONACCI SERIES D. CHECK WHETHER A GIVEN NUMBER IS EVEN OR

ODD E. AREA OF TRIANGLE F. FINDING DISCRIMINANT OF QUADRATIC

EQUATION G. PAYBILL CALCULATION USING SWITCH CASE

STATEMENT H. C PROGRAM TO CALCULATE SIMPLE INTEREST

36 38 40 43

45 47

48

50

10 ARRAYS A. SUM AND AVERAGE OF NUMBERS IN

ARRAY B. DYNAMIC INITIALIZATION OF ARRAY

DURING RUNTIME C. SORT ARRAY ASCENDING AND

DESCENDING D. MULTIPLICATION TABLE USING 2D ARRAY

51

53

55

57

11 STRUCTURE AND UNION 59

12 FUNCTIONS 62

REFERENCES 66

* manual prepared for version OpenOffice.org 1.1.2

v

Page 6: Cp Lab 1 Manual 2009-Srit

1

EX. NO. : 1

WORD PROCESSING DOCUMENT CREATION, TEXT MANIPULATION WITH

SCIENTIFIC NOTATIONS AIM

To create a document in OpenOffice.org Writer in Linux, manipulate text and do

scientific notations.

ALGORITHM

PART A: Document Creation

1. Start OpenOffice.org Writer. On the File menu, click New->Text Document.

2. Create a new blank document and save with extension .doc.

3. Create a web page, on the File menu, click New->HTML Document. Save document

with extension .htm or .html.

4. Create a resume document.

a. Choose Resume template from the Templates and Documents dialog box.

b. Click Open to view the template.

c. Modify resume and save as .doc.

PART B: Text Manipulation

1. On the File menu, click New->Text Document.

2. Type definition of Work Processing. Place the cursor in front of “Word”. Write down

the corresponding action to the following keyboard selections: A. SHIFT+RIGHT ARROW

B. SHIFT+LEFT ARROW

C. CTRL+SHIFT+RIGHT ARROW

D. SHIFT+DOWN ARROW

E. SHIFT+UP ARROW

F. SHIFT+PAGE DOWN

G. SHIFT+PAGE UP

Page 7: Cp Lab 1 Manual 2009-Srit

H. CTRL+SHIFT+HOME

I. CTRL+SHIFT+END

J. CTRL+A

PART C: Formatting the document

1. Open a new document by choosing File->New->Text Document.

2. Set up the page by using Format->Page.

a. Set Margins, Left: 1.25 inch, Right: 1 inch, Top: 1.25 inch, Bottom: 1.25 inch.

b. Set Paper Size to A4.

c. Set Page Layout as Left and Right.

3. Go to Insert->Header->Default.

a. Type your name on the left,

b. Type “SRIT-CSE/CIVIL” in the center and

c. Type today's date on the right.

4. Go to Insert ->Footer->Default and type “Contact me @ <insert your email

address>”.

5. To format Text, type “Watches for Sale”. Select text.

a. Click the Bold icon and give a center alignment by pressing the centered icon

in the object bar.

b. Go to Format->Character-> Font Effects and check Shadow option. Press

'OK'.

c. Set Font size to 16pt.

6. Insert the graphic by clicking Insert->Graphics->From File. Insert an image of a

watch.

7. Type the features of the watch such as Brand Name, Case Color, Case Material etc.

Brand Name: CITIZEN

Case Color : Black

Case Material : Stainless steel.

2

Page 8: Cp Lab 1 Manual 2009-Srit

3

8. To create a hyperlink for the brand name, select “Citizen”, go to Format->Character

and choose the Hyperlink tab. Enter the website address in URL field. Press 'OK'.

9. To format character, type the following

List Price : $215.00

Price: $129.00

Save Up to : $86 (40%).

a. Select List Price “$215.00”. Go to Format->Character. Choose the Font

Effects tab. In the Strikethrough option give single. Press 'OK”.

b. Price “$129.00”. Go to Format->Character. Choose Font Color as Red.

Choose Font Size as 14pt.

10. Enter Product features in a bulleted list. Go to Format->Bullets and Numbering.

Choose solid circled bullets.

11. To change line spacing, go to Format->Paragraph, choose 1.5 line spacing.

12. Highlight the entire bulleted list.

a. Go to Format->Paragraph.

b. Choose 1.5 Line Spacing from the option box.

c. Write down the corresponding Format to the following keystrokes.

Keystroke Format

CTRL-1

CTRL-5

CTRL-2

CTRL-0

13. To change case, type “In Stock”, go to to Format->Case/Characters->Uppercase.

14. To change orientation, Type “SEIKO”, go to Format->Position->Rotation. Choose 90

degrees.

15. To insert symbol, go to Insert->Special Character and insert the '©' symbol. Type

your name.

16. Save documents as .doc.

17. Close the document.

PART D: Scientific Notations

1. Open a new document by choosing File->New->Text Document.

Page 9: Cp Lab 1 Manual 2009-Srit

2. Type the formulas as H2O, A2+B2.

3. Select the 2 in H2O, then choose Format->Character->Position as subscript.

4. Select the 2 in A2+B2, then choose Format->Character->Position as superscript.

5. Insert a formula object by using the option Insert->object->formula bar.

Type the following formula b b2 4ac

2a

a. Alternatively, Write down the corresponding formula in the editor.

{+-b sqrt{b sup 2 - 4ac}} over {2a }

b. Write down all the unary binary operators, relations, set operations, functions,

operators, attributes and brackets.

c. Save the document as formulas.sxw and Close.

4

Page 10: Cp Lab 1 Manual 2009-Srit

SAMPLE OUTPUT

5

WWAATTCCHHEESS FFOORR SSAALLEE

BRAND NAME:CITIZENCASE COLOUR:BLACK

CASE MATERIAL: PLATIUM FOB CHAIN

LIST PRICE:$215.00 PRICE:$129.00

SAVE:89.00(40%)

• WATER RESISTANT

• DURABLE

IN STOCK

TITAN

©NANDHA KUMAR

H2O A2+B2

b b2 4ac2a

Page 11: Cp Lab 1 Manual 2009-Srit

6

EX. NO. : 2

WORD PROCESSING TABLE CREATION, TABLE FORMATTING AND

CONVERSION AIM

To create a table, do formatting and conversion in OpenOffice.org Writer.

ALGORITHM

PART A: Table Creation and Formatting

18. Open a new document by choosing File->New->Text Document.

19. Give title as “TIME TABLE CSE SEMESTER 1 2009/10 ”.

20. Create a table. Go to Insert -> Table. Alternatively, click the Inert table icon in the

main toolbar. Choose 8 columns and 6 rows.

21. Go to View->Toolbars->Customize. Choose Tables toolbar.

22. Type your class timings in the first row and days (Mon-Fri) in the first column.

23. To insert column, go to Format->Column->Insert or press the Insert Row icon in the

Table toolbar or right click->Column->Insert.

a. Select the amount and position.

b. Insert columns for lunch break and tea break.

24. To insert row go to Format->Row->Insert. Specify amount and position. Insert a

row after Friday. Enter “Saturday”.

25. To delete a row, place cursor on row to be deleted and press the Delete Row icon or

right-click->Row->Delete or Format->Row->Delete. Insert another row and delete

it.

26. To merge cells, select cells to be merged and either press the Merge cells icon or

right-click->Cell->Merge Cells or Format->Cell->Merge Cells.

a. Merge all the periods for Labs.

b. Merge all periods for Saturday and Type – Holiday

Page 12: Cp Lab 1 Manual 2009-Srit

7

c. Merge all the cells in column for lunch and tea break.

27. To split cells, select cells to be split and either press the Split cells icon or right-click

->Cell->Split Cells or Format->Cell->Split Cells. Select the Holiday cell and split

into 2.

28. Select the table created. Go to Format->Table. Go to the Borders tab. Give line

style 2.50pt.

29. To select row height and width, select the table.

a. To set row height go to Format-> Row-> Height. Give 0.5 inch.

b. To set column width go to Format ->Column->Width.

PART B: Sorting and Performing Calculation

1. Give title as MY MARKS. Create a new table with 2 columns, Subject and Marks

Obtained.

2. Select the subjects and marks. Go to Tools->Sort.

a. Check Key 1, column 1, Key Type: Alphanumeric, Order: Ascending,

Direction: rows. Press Ok, and write output.

b. Check Key 1, column 2, Key Type: numeric, Order: descending, Direction:

rows.

3. To calculate sum of all marks click Formula icon, enter the formula in editor.

4. Calculate the percentage by giving the formula in the editor.

PART D: Conversion

1. To convert text to table.

a. Type months of a year separated by tabs or semicolons or paragraphs.

b. Go to Tools -> Text <-> table.

c. Choose the mode of separation, eg. semicolons.

2. Convert the table back into text.

PART E: Autoformat Table Creation

1. Create table from Autoformat. Go to Insert->Table->AutoFormat.

2. Create a calendar for this month.

Page 13: Cp Lab 1 Manual 2009-Srit

8

SAMPLE OUTPUT Part A: Table Creation and formatting

TIME TABLE CSE SEMESTER 1 2009/10 8.45 -

9.40 9.40-10.35

10.50-11.45

11.45-12.40

1.45 -2.40

2.40- 3.30

3.30 -4.30

Monday

Tuesday

Wednesday

Thursday

Friday

Saturday HOLIDAY

Part B: Sorting and Performing Calculation

MY MARKS Subject Marks

Chemistry 95 Maths 50 Physics 85 Total 230 Percentage 46.00% Part C: Conversion of Text to table, Table to text January February March January ; February ; March; Part D: Autoformat Table Creation Mon Tue Wed Thu Fri Sat Sun

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 30 31

Page 14: Cp Lab 1 Manual 2009-Srit

9

EX. NO. : 3

WORD PROCESSING MAIL MERGE AND LETTER PREPARATION

AIM

To quickly produce personalized letters and mailing labels using Mail merge feature in

OpenOffice.org.

ALGORITHM Part A: Creation of the Address Book

1. Create a spreadsheet, go to File->New->Spreadsheet.

2. Type First Name, Last Name, Street, City, State, Zip code from columns A1 to F1.

3. Add addresses of 3 people.

4. Save the spreadsheet as addressBook.sxc in a folder named “Mail Merge Lab”.

Part B: Creation of Mail Merge

1. Open writer, go to File->New->Text Document.

2. To register addressBook as Data Source, go to File->Templates->AddressBook

Source.

3. Click on the Administrate… button and create a New Data Source. In the general tab,

choose Name: address. Choose Database type: Spreadsheet. Choose the Path

where addressBook.sxc is stored in Data Source URL. Click ok.

4. In the templates: Address Book Assignment Dialog box, choose Data Source:

Address, Table: Sheet 1.

5. Do Field assignment for the address.

6. Prepare a letter for “Offer for admission to B.E.”.

7. In the To, address, create fields from the data source. Go to View->Data Sources or

click the Data source icon in main toolbar.

8. To insert fields for mail merge, go to Insert->Fields->Other. In the Database tab,

choose Type as Mail Merge Fields. In sheet 1, choose “First Name” and click Insert.

Repeat to insert other fields.

Page 15: Cp Lab 1 Manual 2009-Srit

10

9. To do Mail Merge, go to Tools->Mail Merge. Choose option “From this

Document”. In Mail Merge Dialog Box,

a. Navigate to Sheet 1 and choose all 3 records.

b. Choose Output: File option.

c. Set the Path to the folder called Mail Merge.

d. Choose Generate File Name from Database field “First Name”.

Part C: Autopilot Letter Creation.

1. Create Folder lettersMM.

2. To create letter, go to Autopilot->Letter. Follow the wizard. In addressee data,

choose database as Address and Sheet 1.

3. Write letter for “Leave Letter” and do mail merge. Create a folder called “letterMM”.

Set Path to this folder.

Part D: Mailing Label

1. Create Folder labelsMM.

2. Open new document. Save as “mailingLabel.sxw”. Go to File->New->Labels.

3. Choose Database as Address and Table as Sheet 1.

4. Click on New Document. Create a folder called “labelsMM” Follow steps for mail

Merge, and set Path to labelsMM.

Part E: Creation of Envelope

1. Create Folder EnvelopesMM.

2. Open new document. Save as “Envelope.sxw” Go to Insert->Envelope.

3. Set addressee data from database. Enter your address as sender.

4. Go to Format tab to change the position and size.

5. Go to the Printer tab to change the orientation of the envelope.

6. Click on Insert to Insert the Envelope. Write output.

7. Perform Mail merge and save in folder called “EnvelopeMM”.

Page 16: Cp Lab 1 Manual 2009-Srit

SAMPLE OUTPUT Part B: Creation of Mail Merge

SRI RAMAKRISHNA INSTITUTE OF TECHNOLOGY Pachapalayam, Perur, Chettipalayam, Coimbatore – 641 010

Date: 15th October 2009 Dear Candidate,

Offer of Admission to B.E.(CSE) With reference to your application, we are pleased to inform you that we are admitting you in B.E in the branch of Computer Science and Engineering in the academic year of 2009/2010. Please bring along all the original certificates. The classes will commence on 7th September 2009. PRINCIPAL To, <First Name> <Last Name>, <Street>, <City>, <State>, <Zip Code> Part C: Autopilot Letter Creation. 11

Page 17: Cp Lab 1 Manual 2009-Srit

12

Page 18: Cp Lab 1 Manual 2009-Srit

Part D: Mailing Label

13

Page 19: Cp Lab 1 Manual 2009-Srit

Part E: Creation of Envelope

14

Page 20: Cp Lab 1 Manual 2009-Srit

15

EX. NO. : 4

WORD PROCESSING DRAWING – FLOWCHART

AIM To use drawing tools in OpenOffice.org to draw flow charts.

ALGORITHM Part A: Basic Drawing Functions.

1. Open a new document, go to File->New->TextDocument.

2. Click on the Draw Functions icon in the main toolbar. Click and drag the Drawing

toolbar to create a floating toolbar.

3. To view a grid, go to Tools->Options. Expand Text. Check “Visible Grid”.

4. To wrap text around object, go to Format->Wrap->Edit. Choose

a. No Wrap

b. Parallel

c. Through

d. Optimal

5. To arrange objects, go to Format->Arrange. Choose

a. Bring to Front

b. Bring Forward

c. Send Backward

d. Send to Back

6. Using the drawing toolbar draw

a. Rectangle,

b. Square, choose Rectangle tool and hold shift button.

c. Parallelogram, Go to Format->Position and Size->Slant and set Angle.

d. Diamond, Draw square, Go to Format->Rotation, set 45 degrees.

e. Circle, choose elipse tool and hold shift button.

f. Triangle, using polygon tool.

Page 21: Cp Lab 1 Manual 2009-Srit

7. To group, select all objects by holding Shift button and clicking on the object. Go to

Format->Group->Group.

8. To flip Vertically go to, Flip->Vertically. To flip Horizontally, go to Flip-

>Horizontally.

Part B: Flow Chart

1. To draw a flow Chart for

a. Withdraw cash from ATM.

b. To check whether a given number is even or odd.

2. Draw ellipses/circles for Start and Stop.

3. To enter text, choose the Text tool and double click on object to enter text.

4. Draw parallelograms for input and output.

5. Draw rectangles for processes or events.

6. Draw diamonds for decision boxes having Yes or No decisions.

7. Use arrows to denote the flow of the program.

16

Page 22: Cp Lab 1 Manual 2009-Srit

SAMPLE OUTPUT Part B: Flow Chart - Withdraw cash from ATM

Start

Enter Account Number, pincode

Validate account

Is Valid?

Enter Withdrawal amount

Balance > Withdrawal

Dispense cash

Print Insufficient Balance

Print receipt

End

No

Yes

No

Yes

17

Page 23: Cp Lab 1 Manual 2009-Srit

Part B: Flow Chart - To check whether a given number is even or odd.

Start

Enter a number

Divide number by 2

Is remainder 0?

Print number is Even

Print number is Odd

End

No Yes

18

Page 24: Cp Lab 1 Manual 2009-Srit

19

EX. NO. : 5

SPREADSHEET LINE, XY, BAR and PIE

AIM

To create Line charts, Bar charts, Pie charts and XY Plots using Spreadsheet in OpenOffice.org

Calc.

ALGORITHM

Part A: Line Chart

1. To open spreadsheet, go to Applications->Office->Spreadsheet/OpenOffice.org Calc.

2. Enter the data for drawing a line chart for weather forecast for this week.

3. To insert a chart, go to Insert->Chart.

a. Check ‘First row as label’ and ‘First column as Label’.

b. Choose ‘Line Chart’, press next.

c. Choose data series in ‘Columns’.

d. Check grid lines for both rows and columns. Press Next

e. Give Chart Title as ‘Weather Forecast in Coimbatore for this week’.

f. Give axes titles for X-axis: Days of the week, Y-axis: Temperature/degrees.

g. Click ‘Create’.

4. To format the chart area, double click on the chart. Go to the ‘Area’ tab and give color

as ‘White’.

5. To format the data lines, doubles click on the data series line on the graph.

a. Go to the ‘line’ tab, set appropriate color, width as 0.02.

b. To show data value on graph, go to the ‘Data labels’ tab, Check the show

value checkbox.

6. To format labels along the axis,

a. Double-click Y axis.

b. To change the scale, go to the Scale tab.

c. Set Major Interval as ‘2’.

d. Double-click X axis.

e. To change the orientation of the labels, go to ‘label’ tab, give a rotation of 60

degrees.

Page 25: Cp Lab 1 Manual 2009-Srit

20

7. Rename the sheet, right-click on sheet 1->Rename, give name as ‘Line Chart’.

8. To insert a new sheet, go to Insert->Sheet.

9. To save spreadsheet, go to File->Save As, .sxc (OpenOffice.org Format) and .xls

(Microsoft Excel).

Part B: Bar Chart

1. In a new sheet named ‘Bar Chart’, construct a Vertical and Horizontal bar chart for the

following data, write procedure for the creation of bar chart.

2. Construct a side-by-side double bar chart for the following frequency table.

Part C: Pie Chart

Create a pie chart using the following data. Give chart Title: ‘Country Wise export of

tea from India from 2005-2006’. For each share in the pie chart, create data label of the

importing country and quantity of export as percentage.

Create a 3D pie chart.

Part D: XY Plot

Create an XY plot. Name it ‘The Impact of Moore’s Law’. Set the name of the IC’s

and Microprocessors in the first column as a data label. Set the Y axis from 2000. (Hint: Go to

Scale Tab in Data Point).

Page 26: Cp Lab 1 Manual 2009-Srit

SAMPLE OUTPUT

Part A: Line Chart

Temperature (degrees)

Day Morning Afternoon Evening Sat 30 33 24 Sun 26 29 25 Mon 25 30 25 Tue 25 32 25 Wed 26 31 25 Thu 25 30 24 Friday 24 30 23

Weather forecast for Coimbatore this week

3026 25 25 26 25 24

3329 30

32 31 30 30

24 25 25 25 25 24 23

0

5

10

15

20

25

30

35

Sat Sun Mon Tue Wed Thu Friday

Days of the Week

Tem

pera

ture

/ de

gree

s

Morning AfternoonEvening

21

Page 27: Cp Lab 1 Manual 2009-Srit

Part B: Bar Chart

Month No. of visitors

January 150 February 300 March 250

OUTPUT

Frequency of Visiters to the Museum

150

300

250

0 100 200 300 400Janu

ary

Februa

ry

March

Mon

th

No. of Visiters

Frequency of Visiters to the Museum

150

300

250

0

50

100

150

200

250

300

350

January February March

Month

No. o

f Vis

iters

Side by Side Bar Chart

Month No. of adult Visitors

No. of Child visitors

May 300 200 June 500 600 July 700 600

Frequency of Visitors to the Museum

300

500

700

200

600 600

0100200300400500600700800

May June July

Month

No.

of V

isito

rs

No. of adultVisitorsNo. of Childvisitors

22

Page 28: Cp Lab 1 Manual 2009-Srit

Part C:Pie Chart

Importing Country

Quantity of export (%)

Russia 17.48 UK 15.8 UAE 15.16 USA 7.31 Kazakhstan 6.18 Iran 4.99 Germany 3.84 Pakistan 3.07 Australia 2.88 Saudi Arabia 2.72 Other countries 20.59

Country Wise export of tea from India from 2005-2006

Russia 17%

UK 16%

UAE 15%

Australia 3%

Saudi Arabia 3%

Other countries

21%

USA 7%

Iran 5%

Germany 4%

Pakistan 3%

Kazakhstan 6%

Russia UK UAE USA Kazakhstan Iran Germany Pakistan Australia Saudi Arabia Other countries

23

Page 29: Cp Lab 1 Manual 2009-Srit

Part D: XY Plot

Year of Introduction Transistors

4004 1971 2300

8008 1972 2500

8080 1974 4500

8086 1978 29000

Intel 286 1982 134000

Intel 386 1985 275000

Intel 486 1989 1200000

Intel Pentium 1993 3100000

Intel Pentium II 1997 7500000

Intel Pentium III 1999 9500000

19701975

19801985

19901995

20002000

1002000

2002000

3002000

4002000

5002000

6002000

7002000

8002000

9002000

400480088080 8086 Intel 286Intel 386

Intel 486

Intel Pentium

Intel Pentium II

Intel Pentium III

Impact of Moore's Law

Transistors

Year of Introduction

No.

of T

rans

isto

rs

24

Page 30: Cp Lab 1 Manual 2009-Srit

25

EX. NO. : 6

SPREADSHEET FORMULA EDITOR

AIM

To create and edit formulas and use built in formulas using Formula Editor in

OpenOffice.org Calc Spreadsheet.

ALGORITHM

Part A: Entering Formula, Auditing and Error Codes

1. To open, go to OpenOffice.org Calc Spreadsheet.

2. Enter the following data, starting from cell address A1.

3. To concatenate strings, use the &(ampersand) operator. Place cursor in cell C2, type,

=A2&” “&B2. Alternatively, type =, click A2, type &” “&, click B2. To copy the

formula, copy then paste in cells C3 to C6.

4. To enter basic arithmetic operators, place cursor in cell F2 (Total), Type, = D2+E2. Copy

and paste in cells F3 to F6.

5. To select a range, use the : (colon) operator.

6. To insert a function, place cursor in cell D7, go to Insert->Function.

1. Choose category, mathematical, choose SUM.

2. Select cells D2 to D6 or type formula, = SUM(D2:D6)/5 to calculate average.

3. Copy and paste formula in E7.

Note: Spreadsheet uses relative reference.

7. To perform calculations on another worksheet, go to Sheet 2, Type Total in A1. In A2,

type =, then click Sheet 1. Choose cells corresponding to Test 1. Observe the formula in

Sheet 2.

8. To protect sheet, select cells in Total (F2 to F6)

1. Go to Format->Cells->Protection->Cell Protection.

2. Check 'Hide Formula'. Press OK.

3. Go to Tools->Protect Document->Sheet. Press OK. Now try to edit formula. Write

down the message obtained after protection.

9. To audit and correct errors. Try to multiply cell B2*D2:D6.

a) Click on the error, go to Tools->Detective->Trace Error. Draw the arrows resulting in

Page 31: Cp Lab 1 Manual 2009-Srit

26

the mistake.

b) Go to Tools->Detective->Remove Precedents to remove the arrows.

10. Write down the reasons for the following error codes (Look up in Help)

#N/A, #NULL, #NUM!, ####, #VALUE!, #NAME?, #REF!, #DIV/0!. Also write down

possible examples where this error occurs.

Part B: Commonly Used Formulas

3. Enter the following data for a set of bank transactions.

4. To calculate Tax, IF salary >10000, Tax is 20% of Salary, else Tax is 10%. Eg.,

=IF(D3>10000;20/100*D3;10/100*D3).

5. To calculate Running Balance, Type, = Salary – (Tax + Withdrawal) + Deposit, eg, =D3-

(E3+F3)+G3

6. To count the occurences of transactions with billing date on 2nd oct, go to cell D8, type,

=COUNTIF (C3:C6;"02/10-09").

7. Choose the sheet and protect it.

Part C: Built In Functions

Mathematical Functions

1. Insert new sheet, go to Insert->Sheet, To use SUM, POWER, PRODUCT,

a) Convert 756 in octal to decimal, enter in A1:7, B1:5, C1:6. , in A2,

b) Type = POWER(8 ; 2), B2, =POWER(8 ; 1), C2, =POWER(8 ; 0).

c) In A3, type =PRODUCT(A1 ; A2). Copy and paste formula to B3 and C3.

d) Add A3 to C3 to get value in decimal.

2. Find the QUOTIENT of 5/2.

3. ROUND number 2.149 to 1 decimal place.

4. Enter 5 numbers, find MAXIMUM value.

Trigonometrical Functions

5. Enter the following data, to perform Trigonometrical functions., calculate SIN, COS, TAN

using the functions, write formula, insert a seperate chart for sin, cos and tan.

6. Perform conversion between various number systems

Logical Functions

7. To determine logical conditions, use AND, OR, NOT functions

Page 32: Cp Lab 1 Manual 2009-Srit

27

TEXT FUNCTIONS

2. To work with text, enter the following data

a. Concatenate First Name and last name using CONCATENATE function

b. Change the full name to upper case using UPPER function.

c. Change the full name from upper to lower case using LOWER function.

Page 33: Cp Lab 1 Manual 2009-Srit

28

SAMPLE OUTPUT

Part A: Entering Formula, Auditing and Error Codes

First Name Last Name Full Name Test 1 Test 2 Total

Divya Kumar Divya Kumar 25 20 45 Johnny Lane Johnny Lane 30 25 55 Vidya Karan Vidya Karan 35 31 66 Varun Sharma Varun Sharma 15 35 50 Rose Reynolds Rose Reynolds 25 36 61 Sum 130 147 Average 26 29.4

Syntax of formulas used: Full Name =A2&” “&B2 Total = E2+F2 Test 1 Total = SUM(D2:D6) Test 1 Average = AVERAGE(D2:D6) Part B: Commonly Used Formulas

BANK TRANSACTIONS

Acc No. Name Billing Date Salary Tax Withdrawal Deposit Running Balance

101 Jane 2/10/2009 10000 1000 500 1000 9500 102 Michael 2/10/2009 5000 500 0 5000 9500 103 Priya 4/10/2009 15000 3000 10000 0 2000 104 Prasanna 5/10/2009 30000 6000 5000 2000 21000

Syntax of formulas used: Tax =IF (D3>10000;20/100*D3;10/100*D3) Balance =D3-(E3+F3)+G3 Part C: Built In Functions - Mathematical Functions

Degrees sin cos Tan 0 0 1 0

45 0.7071 0.707107 190 1 6.13E-17 1.6325E+16

135 0.7071 -0.70711 -1180 1E-16 -1 -1.2251E-16225 -0.707 -0.70711 1270 -1 -1.8E-16 5.4415E+15315 -0.707 0.707107 -1360 -2E-16 1 -2.4503E-16

Page 34: Cp Lab 1 Manual 2009-Srit

Syntax of formulas used: sin =SIN(RADIANS(B2)) cos =COS(RADIANS(B2)) tan = TAN(RADIANS(B2))

sin

-1.5

-1

-0.5

0

0.5

1

1.5

0 30 60 90 120 150 180 210 240 270 300 330 360sin

CONVERSION FUNCTIONS Conversion Number Answer Decimal to Binary 29 11101Decimal to Octal 952 1670Decimal to Hexadecimal 872 368Binary to decimal 1100000 96

Syntax of formulas used: =DEC2BIN(B2) =DEC2OCT(B3) =DEC2HEX(B4) =BIN2DEC(B5) LOGICAL FUNCTIONS

a b D = a AND b E= a OR b F= NOT a D AND F 0 0 FALSE FALSE TRUE FALSE 0 1 FALSE TRUE TRUE FALSE 1 0 FALSE TRUE FALSE FALSE 1 1 TRUE TRUE FALSE FALSE

Syntax of formulas used: D =AND(A2;B2) E =OR(A2;B2) F =NOT(A2) D AND F =AND(C2;E2) 29

Page 35: Cp Lab 1 Manual 2009-Srit

30

TEXT FUNCTIONS

First Name Last Name Full Name To Upper To lower Jenna Dewan Jenna Dewan JENNA DEWAN jenna dewan

Michael Phelps Michael Phelps MICHAEL PHELPS michael phelps

Ray Romano Ray Romano RAY ROMANO ray romano Syntax of formulas used: =CONCATENATE(A2;” “;B2) =UPPER(C2) =LOWER(D2)

Page 36: Cp Lab 1 Manual 2009-Srit

EX. NO. : 7

SPREADSHEET INCLUSION OF OBJECT, PICTURE AND GRAPHICS, PROTECTING THE

DOCUMENT AND SHEET

AIM

To include objects, Pictures and graphics and to protect the document and sheet in

OpenOffice.org Calc Spreadsheet.

ALGORITHM

Part A: Working with Picture and Graphics.

1. To open spreadsheet, go to Applications->Office->OpenOffice.org Calc.

2. To insert a picture on a worksheet, choose, Insert->Graphics->From File or go to

Tools->Gallery to select an image.

3. To resize the object, select object, drag sizing handle.

a. To resize proportionally, hold SHIFT and drag corner of sizing handle.

b. To resize vertically, horizontally or diagonally from center, hold CTRL and

drag sizing handle.

c. To resize proportionally from center outward, hold CTRL+SHIFT and drag

corner sizing handle.

4. To resize an object by a specific percentage, click the object, go to Format-Position

and Size. Go to Position and Size tab.

a. Choose Base Point as center.

b. Change the size of the image, check ‘Keep Ratio’ to keep the original ratio.

5. To rotate a drawing object, go to drawing Toolbar, click the Free Rotate icon.

a. Drag the rotation handles to rotate the object. ( red circular handles ).

b. To constrain rotation of object to 15 degree angles, hold down SHIFT button.

6. To rotate an object by specifying angles, click object, go to Format->Position and

Size. Go to the Rotation tab. Set a rotation angle of 45 degrees.

Part B: Working with Auto shapes/objects.

311. Include an OLE object, go to Insert->Object->OLE object.

Page 37: Cp Lab 1 Manual 2009-Srit

32

2. Choose ‘Create New’ and object type as Drawing.

3. Draw an autoshape, a smiley using the available shapes.

a. To draw circle, choose an ellipse tool, hold down the SHIFT to maintain

shapes’s width-to-height ration.

b. To draw a curve, point to curves in the drawing toolbar, click whenever to add a

curve. Double click to end the curve. To close the shape click near starting

point. Right-click->Edit Points to edit the points.

4. To insert text, go to the Text tool, Type, “Hello World”

a. To include font work, click the text, go to Format->Font Work. Set the text in

the desired format.

5. To convert to 3D right-click the smiley, go to Convert->3D.

a. To add Shadow, right-click->3D Effects.

b. Set Shading option and shadow.

6. To move stacked objects, click object.

a. If object is hidden behind other objects press TAB or SHIFT+TAB.

7. Convert the smiley to Bitmap, right-click->Convert->Bitmap.

8. Convert the smiley to Metafile, right-click->Convert->Metafile.

Part C: Protecting the Document

1. To protect all documents when saving, go to File->Save As. Check the “Save with

Password” option. Enter the password in the dialog box and save.

2. To protect the cell ranges in a sheet, choose all the cells that span the drawing

a. Go to Format->Cell Protection, Hide All.

b. Go to Tools->Protect->Sheet/Document.

c. Give Password and confirm the given password.

d. To unprotect the sheet/document, go to Tools->Protect->Sheet/Document.

3. To protect frames, graphics and OLE objects and drawing objects, go to Format-

>Position and Size->Position and Size tab. Under Protect, Check Position/Size.

Page 38: Cp Lab 1 Manual 2009-Srit

EX. NO. : 8

SPREADSHEET SORTING AND IMPORT / EXPORT FEATURES

AIM To perform sorting and import/export functions in OpenOffice.org Calc Spreadsheet.

ALGORITHM Part A: Sorting data in a list

1. To sort data in a list, ascending/descending

2. Select all the names. Sort the data in an ascending manner, by clicking the Ascending

Sort from the standard toolbar. Write the output.

3. Sort the data in a descending manner, by clicking the Descending sort from the

standard toolbar. Write the output.

4. Alternatively go to Data->Sort.

a. Click on the Sort By drop down box and choose column name to sort.

b. Click on option Ascending/Descending to specify sort order.

c. Click ok.

5. To sort rows based on the contents of two or more columns, enter the following data.

a. To sort, go to Data->Sort.

b. Choose Sort By Branch, Ascending

c. Then choose Then By Name, Ascending

6. To sort columns based on the contents of rows, enter the following data

a. Select cells, go to Data->Sort.

b. Go the Options tab. Choose Direction as “Left to Right(sort columns)”

c. Click OK, write down output.

7. To sort months, weekdays or custom lists,

a. Select the cells, go to Data->Sort and go to the Options tab.

b. Check “Custom sort order” and choose “Monday, Tuesday,…” from the drop

down menu.

33

Page 39: Cp Lab 1 Manual 2009-Srit

34

Part B: Import/Export

1. List any 10 file formats that is supported by the Calc Spreadsheet Application, Go to

File>Open->File Type.

2. To open a spreadsheet in read-only mode, check the ‘read-only’ box when opening a

file.

3. To import a database into Spreadsheet, go to File->Autopilot->Database Import.

4. To export, go to File->Export as PDF.

5. To export a single OpenOffice file to Microsoft Office file, choose the .xls from Save

As menu.

6. To export multiple OpenOffice files to Microsoft Office, go to Autopilot ->Document

Converter.

a. Set path of folder for importing in Import.

b. Set path for folder to contained converted documents in Save As.

Page 40: Cp Lab 1 Manual 2009-Srit

35

SAMPLE OUTPUT

Part A: Sorting data in a list Ascending Sort

1 Ruby 8 Angela 2 Liz 7 Blaine 3 Maria 4 Emma 4 Emma 10 Jerry 5 Michael 2 Liz 6 Phoenix 3 Maria 7 Blaine 9 Max 8 Angela 5 Michael 9 Max 6 Phoenix

10 Jerry 1 Ruby

Sorting 2 columns Branch Name Branch Name CSE Ruby CIVIL Angel CIVIL Angel CIVIL Maria MECH Blaine CSE Jerry MECH Ricky CSE Liz CSE Phoenix CSE Michael CSE Jerry CSE Phoenix CSE Liz CSE Ruby CIVIL Maria MECH Blaine MECH Max MECH Max CSE Michael MECH Ricky

OUTPUT Sorting left to right

5 8 4 3 2

2 3 4 5 8

Custom Sort

Day Menu Day Menu Tuesday Rice Monday Chappati Thursday Parota Tuesday Rice Monday Chappati Wednesday Thosai Friday Briyani Thursday Parota Wednesday Thosai Friday Briyani

Page 41: Cp Lab 1 Manual 2009-Srit

36

EX. NO. : 9

C PROGRAMMING DATA TYPES, EXPRESSION EVALUATION AND CONDITION STATEMENTS

AREA AND CIRCUMFERENCE OF CIRCLE

AIM To write a program to find the area and circumference of circle.

ALGORITHM

Step 1: Start the program.

Step 2: Get user input for radius of circle.

Step 3: Calculate area of circle by using formula, area = 3.14*radius* radius.

Step 4: Calculate circumference of circle by using formula, circum = 2*3.14*radius.

Step 5: Display area and circumference.

Step 6: Stop the program.

PSEUDOCODE

BEGIN

INITIALIZE PI as 3.14, area, circum, r

READ radius r

CALCULATE area := PI*r*r

CALCULATE circum :=2*PI*r

PRINT area, circum

END

Page 42: Cp Lab 1 Manual 2009-Srit

FLOWCHART

Start

Read radius

Area = 3.14 * radius * radius Circum = 2 *3.14 * radius

Print area Print circum

Stop

PROGRAM

#include<stdio.h> #define Pi 3.14159 main() { float radius,area, circum; printf("Enter radius: "); scanf("%f",&radius); area= Pi * radius * radius; circum = 2 * Pi * radius; printf("\nArea=%0.2f",area); printf("\nCircumference=%0.2f \n",circum); }

OUTPUT: Enter radius: 5 Area=78.54 Circumference=31.42 RESULT Thus, program to calculate area and circumference of circle is executed and output is verified

37

Page 43: Cp Lab 1 Manual 2009-Srit

38

FACTORIAL OF A GIVEN NUMBER AIM To write a program to find the factorial of a given number. ALGORITHM

Step 1: Start the program.

Step 2: Get user input for the factorial number.

Step 3: Set loop to find factorial of given number using formula fact = fact*i.

Step 4: Display the factorial of the given number.

Step 5: Stop.

PSEUDOCODE

BEGIN

INITIALIZE i as 1, fact as 1

READ num

REPEAT

fact := fact*i

INCREMENT i

UNTIL i <= num

PRINT fact

END

Page 44: Cp Lab 1 Manual 2009-Srit

FLOWCHART

Start

Read number

Print factorial

Stop

Initialize i=1, fact=1

fact= fact * i i++

Is i <= num

No

Yes

PROGRAM #include <stdio.h> int main() { int i=1, fact=1; int num; printf("Enter a number: "); scanf("%d", &num); while(i <= num) { fact *= i; i++; } printf("Factorial: %d\n", fact); } OUTPUT Enter a number: 5 Factorial: 120

39Thus, program to find factorial of given number is executed and output is verified.

RESULT

Page 45: Cp Lab 1 Manual 2009-Srit

40

GENERATING FIBONACCI SERIES

AIM e a program to generate Fibonacci series up to a given number.

LGORITHM program.

the number is zero or not. If zero print zero, exit.

nd b=c for every iteration in the loop.

SEUDOCODE

E lim, a, b

1, lim=1

0

b

lim

To writ AStep 1: Start the

Step 2: Enter the limit

Step 3: Check whether

Step 4: Set loop up to given number.

Step 5: Calulate fib= fib + a, set a=b a

Step 6: Print the Fibonacci number in every iteration of the loop.

Step 7: Stop the program.

P

BEGIN

DECLAR

INITIALIZE a=0, b=

fib = a + b

READ num

IF num == 0

PRINT

REPEAT

a =

b= fib

fib = a + b

INCREMENT

PRINT fib

UNTIL lim < num

END

Page 46: Cp Lab 1 Manual 2009-Srit

41

LOWCHART

ROGRAM

include <stdio.h>

t main() {

int fib=1;

printf("Enter the limit: ");

F

Start

Read number

Print 0

Stop

a=0, b=1 fib = a+b

P # in int a=0, b=1; int num, i=0; int lim =0; fib =a+b; scanf("%d", &num);

a=b; b=fib;

fib = a+b; lim++;

Is num == 0

Yes

Yes

Is lim < num

Print fib

No

No

Page 47: Cp Lab 1 Manual 2009-Srit

42

** Generating Fibonacci series...");

"%d", num);

while(lim < num)

=b; b=fib;

;

nter the limit: 5 onacci series... 2 3 5 8 13

ESULT s, program to generate Fibonacci series is generated and output is verified.

printf(" if(num == 0) printf( { a fib = a+b; lim++; printf(" %d", fib) } printf("\n"); } OUTPUT E** Generating Fib R Thu

Page 48: Cp Lab 1 Manual 2009-Srit

43

CHECK WHETHER A GIVEN NUMBER IS EVEN OR ODD AIM

e a program to find out whether a given number is even or odd.

LGORITHM Program.

ue modulo 2.

e given value is even.

d.

SEUDOCODE

E rem

m = val%2

T Value is Even

LSE

RINT Value is ODD

ND

To writ AStep 1: Start the

Step 2: Enter integer value.

Step 3: Determine rem = val

Step 4: Check if rem is 0.

Step 5: If rem is 0, print th

Step 6: If rem is not 0, print the given value is od

Step 7: End.

P

BEGIN

DECLAR

READ val

DETERMINE re

IF rem == 0

PRIN

E

P

E

Page 49: Cp Lab 1 Manual 2009-Srit

FLOWCHART

44

PROGRAM:

Start

Enter value

rem = val % 2

Print odd

Stop

Is rem == 0

Print even

#include<stdio.h> main() { int num,rem; printf("Enter a number: "); scanf("%d",&num); rem=num%2; if(rem==0) printf(" \n The entered number is EVEN \n"); else printf(" \n The entered number is ODD \n"); } OUTPUT Enter a number: 5 The entered number is ODD Enter a number: 2 The entered number is EVEN RESULT Thus program to find whether a given number is even or odd is executed and output is verified.

Page 50: Cp Lab 1 Manual 2009-Srit

45

AREA OF TRIANGLE AIM To write a C program to find the area of triangle ALGORITHM Step 1: Start Step 2: Read the input values of a,b,c; Step 3: Compute s=(a+b+c)/2; Step 4: Compute d=(s*(s-a)*(s-b)*(s-c)) Step 5: Find the area of triangle with the formula area=sqrt(d) Step 6: Print area Step 7: Stop

PSEUDOCODE

DEFINE AS int a,b,c DEFINE AS float s,d,area Input a, b, c CALCULATE s= (a+b+c)/2 CALCULATE area=(s*(s-a)*(s-b)*(s-c)) PRINT area

PROGRAM #include<stdio.h> #include<math.h> main() { float a,b,c; double s,d,area; printf("Enter 3 sides"); scanf("%f %f %f",&a,&b,&c); s=(a+b+c)/2; //d=4; d =(s*(s-a)*(s-b)*(s-c)); area=sqrt(d); printf("Area of triangle= %f sq units\n",area); }

Page 51: Cp Lab 1 Manual 2009-Srit

FLOWCHART

Start

Read a,b,c

s = (a+b+c)/2

Print area

Read s,d,area

d=(s*(s-a)*(s-b)*(s-c))

stop

OUTPUT Enter 3 sides 5 10 8 Area of triangle= 19.810035 sq units RESULT Thus a C program to find the area of triangle was executed and output was verified.

46

Page 52: Cp Lab 1 Manual 2009-Srit

47

FINDING DISCRIMINANT OF QUADRATIC EQUATION

AIM To write a C program to find the discriminant of a quadratic equation. ALGORITHM Step 1: Start Step 2: Read a,b,c Step 3: Calculate sqroot=sqrt(b*b-4*a*c) Step 4: Calculate x1=((-b+sqroot)/2*a) Step 5: Calculate x2=((-b-sqroot)/2*a) Step 6: Display x1,x2 Step 7: Stop PSEUDOCODE BEGIN DEFINE AS int a,b,c DEFINE AS int sqroot, x1,x2 READ a, b, c CALCULATE sqroot = sqrt(b*b – 4*a*c) CALCULATE x1 = ((-b + sqroot) / 2*a) CALCULATE x2 = ((-b - sqroot) / 2*a) PRINT x1, x2 END PROGRAM

#include<stdio.h> #include<math.h> main() { int a,b,c,sqroot,x1,x2; printf("Enter the values of a,b,c : "); scanf("%d%d%d",&a,&b,&c); sqroot = sqrt(b*b-4*a*c); x1=(-b + sqroot) / (2*a); x2=(-b - sqroot) / (2*a); printf(“First root is %d”, x1 printf("Second root is %d", x2); }

OUTPUT RESULT Thus a C program to find the square root of a given number was executed and the output was verified.

Page 53: Cp Lab 1 Manual 2009-Srit

48

PAYBILL CALCULATION USING SWITCH CASE STATEMENT AIM To write a C program for Pay bill calculation using Switch Case statement ALGORITHM

Step 1: Start Step 2: Read the data Step 3: Decide the level number and calculate perks Step 4: Calculate gross salary, income tax Step 5: Compute the net salary Step 6: Display the result Step 7: Stop PSEUDOCODE Define : int level, jobnumber float gross,basic,net,perks Input : level,job number,basic pay Compute: houserent = 0.25*basic Gross = basic + houserent + perks net salary = gross - incometax Output : Display result PROGRAM #define CA1 1000 #define CA2 750 #define CA3 750 #define CA4 750 #define EA1 500 #define EA2 200 #define EA3 100 #define EA4 0 main() { int level,jobnumber; float gross,basic,houserent,perks,net,incometax; input: printf("\n enter level,job number,basic pay\n"); printf("enter 0 for level to end\n\n"); scanf("%d",&level); if(level==0)goto stop; scanf("%f%f",&jobnumber,&basic); switch(level) { case 1: perks=CA1+EA1; break; case 2: perks=CA2+EA2;

Page 54: Cp Lab 1 Manual 2009-Srit

49

break; case 3: perks=CA3+EA3; break; case 4: perks=CA4+EA4; break; default: printf("error in level code\n"); goto stop; } houserent=0.25*basic; gross=basic+houserent+perks; if(gross<=2000) incometax=0; else if(gross<=4000) incometax=0.03*gross; else if(gross<=5000) incometax=0.05*gross; else incometax=0.08*gross; net=gross-incometax; printf("\n\n%d%d%f\n",level,jobnumber,net); goto input; stop:printf("\n\n end the program"); } RESULT Thus a C program for Pay bill calculation using Switch Case statement was executed and output was verified.

Page 55: Cp Lab 1 Manual 2009-Srit

50

C PROGRAM TO CALCULATE SIMPLE INTEREST AIM To write a C program to calculate simple interest using while condition ALGORITHM

1. Start 2. Read the values of amount,inrate 3. Read the values year,period 4. Check the condition whether year<=period 5. Calculate the value by using the formula

a. value=amount +inrate +amount 6. Assign the amount to value and increment the year by 1 7. Stop.

PSEUDOCODE Define : int year,period Float amount,inrate,value Input : amount,rate and period. Condition : while(year<=period) Calculate : value=amount+inrate+amount Output : display result PROGRAM main() { int year,period; float amount,inrate,value; printf("input amount,interest rate and period\n\n"); scanf("%f%f%d",&amount,&inrate,&period); printf("\n"); year=1; while(year<=period) { value=amount+inrate+amount; printf("%d%f\n",year,value); amount=value; year=year+1; } } RESULT Thus a C program to calculate simple interest using while condition was executed and the output was verified.

Page 56: Cp Lab 1 Manual 2009-Srit

51

EX. NO. : 10

C PROGRAMMING ARRAYS

SUM AND AVERAGE OF NUMBERS IN ARRAY

AIM To write a program to initialize an array of 5 numbers and print sum and average

ALGORITHM

Step 1: Start the program

Step 2: Declare and initialize array of size 5.

Step 3: Set loop up to size of array

Step 4: Find sum of array

Step 5: After execution of loop, find average.

Step 6: Print sum and average of array

Step 7: Stop the program.

PSEUDOCODE

BEGIN

DEFINE N AS 5

INITIALIZE integer array to size 5, i=0, and sum = 0

REPEAT

Sum = sum+arr[i]

UNTIL i < size

CALCULATE avg = sum/N

PRINT sum, avg

END

Page 57: Cp Lab 1 Manual 2009-Srit

52

PROGRAM #include<stdio.h> #define N 5 int main() { int arr[] = {10,2,5,1,25}; int i, temp, j; printf("\n\t Before Sorting: "); for(i=0; i<N; i++) printf("%d ",arr[i]); for(i=0; i<N; i++){ for(j=i+1; j<N; j++){ if(arr[i]>arr[j]) { temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } // end if }// end inner for loop }// end outer for printf("\n\n** Sorting the array in Descending order...\n"); printf("\n\tAfter Sorting: "); for(i=0; i<N; i++) printf("%d ", arr[i]); printf("\n\n\t** Max Number: %d", arr[0]); printf("\n\t** Min Number: %d\n", arr[N-1]); printf("\n"); return 0; } OUTPUT Before Sorting: 10 2 5 1 25 ** Sorting the array in Descending order... After Sorting: 1 2 5 10 25 ** Max Number: 1 ** Min Number: 25 RESULT Thus, program to initialize an array of 5 numbers and print sum and average is executed and output is verified.

Page 58: Cp Lab 1 Manual 2009-Srit

53

DYNAMIC INITIALIZATION OF ARRAY DURING RUNTIME

AIM To write a program to initialize array dynamically during runtime to calculate sum and

average for a given number of values specified by user.

ALGORITHM

Step 1: Start the program

Step 2: Enter the number of array

Step 3: Enter the elements of array

Step 4: Set loop up to size of array

Step 5: Find sum of array

Step 6: After execution of loop, find average of array.

Step 7:Print sum and average of array

Step 8: Stop the program.

PSEUDOCODE

BEGIN

INITIALIZE integer array to size 100, val, num, i=0, and sum = 0

PRINT number of values to enter

READ number into num

REPEAT

PRINT enter value i+1

READ value into arr[i]

DETERMINE sum = sum+ arr[i]

UNTIL i < num

CALCULATE avg = sum/num

PRINT sum, avg

END

Page 59: Cp Lab 1 Manual 2009-Srit

54

PROGRAM #include <stdio.h> int main() { int arr[100]; int sum=0, val, num; float avg; int i; printf("How many values do you wanna enter?" ); scanf("%d",&num); for(i=0; i<num; i++) { printf("\n Enter Value: "); scanf("%d", &val); arr[i] = val; } for(i=0; i<4; i++){ printf("\n Value %d: %d: ", i+1, arr[i]); sum +=arr[i]; } avg=sum/4; printf("\n\t Sum = %d", sum); printf("\n\t Average = %.2f \n", avg); return 0; }

OUTPUT How many values do you wanna enter?5 Enter Value: 45 Enter Value: 98 Enter Value: 85 Enter Value: 79 Enter Value: 65 Value 1: 45: Value 2: 98: Value 3: 85: Value 4: 79: Sum = 307 Average = 76.00 RESULT Thus, program to initialize array dynamically and print sum and average is executed and output is verified.

Page 60: Cp Lab 1 Manual 2009-Srit

55

SORT ARRAY ASCENDING AND DESCENDING AIM

To write a program to sort a given array of variables in ascending and descending

order.

ALGORITHM

Step 1: Start the program

Step 2: Initialize size of array as N

Step 3: Initialize elements of array to N numbers

Step 4: Set loop to array size minus 1

Step 5: Set inner loop to array size

Step 6: Check whether next array element si greater than current element

Step 7: If greater exchange position.

Step 8: If not greater, then go to loop

Step 9: After execution of inner loop, inner loop is executed.

Step 10: Print ascending order of given array.

Step 11: Print descending order of given array

Step 12: Stop the program.

PSEUDOCODE

BEGIN

INITIALIZE integer array to size N

REPEAT

REPEAT

IF arr[i] > arr[j] THEN

SET temp = arr[i]

STORE arr[i] = arr[j]

SET arr[j] = temp

INCREMENT j

UNTIL j < N

INCREMENT i

UNITIL i<N-1

PRINT array in ascending order

PRINT array in descending order

Page 61: Cp Lab 1 Manual 2009-Srit

56

PRINT max Num AS arr[N-1]

PRINT minNum AS arr[0]

END

PROGRAM #include<stdio.h> #define N 5 int main() { int arr[] = {10,2,5,1,25}; int i, temp, j; printf("\n\t Before Sorting: "); for(i=0; i<N; i++) printf("%d ",arr[i]); for(i=0; i<N; i++){ for(j=i+1; j<N; j++){ if(arr[i]>arr[j]) { temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } // end if }// end inner for loop }// end outer for printf("\n\n** Sorting the array in Ascending order...\n"); for(i=0; i<N; i++) printf("%d ", arr[i]); printf("\n\n** Sorting the array in Descending order...\n"); for(i=N-1; i>=0; i--) printf("%d ", arr[i]); printf("\n\n\t** Max Number: %d", arr[0]); printf("\n\t** Min Number: %d\n", arr[N-1]); printf("\n"); return 0; } OUTPUT Before Sorting: 10 2 5 1 25 ** Sorting the array in Ascending order... 1 2 5 10 25 ** Sorting the array in Descending order... 25 10 5 2 1 ** Max Number: 1 ** Min Number: 25 RESULT Thus, program to sort a given array of variable size in ascending and descending order is executed and output is verified.

Page 62: Cp Lab 1 Manual 2009-Srit

57

MULTIPLICATION TABLE USING 2D ARRAY AIM

To write a program to display multiplication table using 2 dimensional array

ALGORITHM

Step 1: Start the program

Step 2: Define ROWS, COLUMNS

Step 3: Declare a 2D array, Product

Step 4: Set loop to size of COLUMNS

Step 5: Set inner loop to size of ROWS

Step 6: Calculate and print product

Step 7: Stop the program.

PSEUDOCODE

BEGIN

DEFINE ROWS AS 5, COLUMNS AS 5

INITIALIZE array Product to ROWS and COLUMNS

SET i=0, j=1

REPEAT

PRINT COLUMNS label

UNTIL i<= COLUMNS

REPEAT

PRINT ROWS label

SET row = i+1

REPEAT

SET column=j

CALCULATE product[i][j] = rows*columns

PRINT product[i][j]

UNTIL j<= COLUMNS

UNTIL i<= ROWS

END

Page 63: Cp Lab 1 Manual 2009-Srit

58

PROGRAM #include <stdio.h> #define ROWS 5 #define COLUMNS 5 int main() { int row, column; int product[ROWS][COLUMNS]; // result of multiplication int i,j; printf("\n\n** Multiplication Table **\n\n"); printf(" "); for(j=1; j<= COLUMNS; j++) printf(" %4d", j); printf("\n"); printf("________________________________\n"); for(i=0; i<+ROWS; i++) { row = i+1; printf("%2d |", row); for(j=1; j <= COLUMNS; j++) { column = j; product[i][j] = row * column; printf(" %4d", product[i][j]); } // end inner for - COLUMNS printf("\n"); } // end outer for - ROWS return 0; } OUTPUT ** Multiplication Table ** 1 2 3 4 5 ________________________________ 1 | 1 2 3 4 5 2 | 2 4 6 8 10 3 | 3 6 9 12 15 4 | 4 8 12 16 20 5 | 5 10 15 20 25 RESULT Thus, program to display multiplication table using 2D array is executed and output is verified.

Page 64: Cp Lab 1 Manual 2009-Srit

59

EX. NO. : 11

C PROGRAMMING STRUCTURES AND UNIONS

AIM

To write a program using structures and unions store student details and find average

and grade for a set of students.

ALGORITHM

Step 1: Start the program

Step 2: Initialize the structure and union variable.

Step 3: Set a loop up to the number of students.

Step 4: Enter name, register number and marks for 3 tests and store in the structure variable.

Step 5: Calculate average and grade and store in the union variable.

Step 6: print the student name, register number, marks for 3 tests, average and grade for all the

students.

Step 7: Stop the program.

PSEUDOCODE

BEGIN

INITIALIZE structure student as stud[50] and union result as res[50]

READ number of students AS no

REPEAT

READ name and reg no, test 1, test 2, test 3 marks of student

STORE in structure variable

CALCULATE res[i].avg = (stud[i].test1 +stud[i].test2+stud[i].test3)/3

DETERMINE grade

IF res[i].avg>50 AND res[i].avg<60

SET grade AS D

ELSE IF res[i].avg>=60 AND res[i].avg<70

SET grade AS C

ELSE IF res[i].avg>=70 AND res[i].avg<80

SET grade AS B

ELSE IF res[i].avg>=80 AND res[i].avg<=100

Page 65: Cp Lab 1 Manual 2009-Srit

60

SET grade AS A

ELSE

SET grade AS F

INCREMENT i by 1

UNTIL i<no

PRINT details of students.

END

PROGRAM #include <stdio.h> main(){ struct student{ char name[25]; char regno[25]; int test1, test2, test3; }stud[50]; union result{ char grade; float avg; }res[50]; int i, no; int test1, test2, test3; printf("Enter number of students:"); scanf("%d", &no); for(i=0; i<no; i++) { printf("-- Enter details of student %d--\n", i+1); printf("Enter name: "); scanf("%s", &stud[i].name); printf("Enter regno: "); scanf("%s", &stud[i].regno); /* Enter 3 marks and find average */ printf("Enter 3 test marks: "); scanf(" %d %d %d", &stud[i].test1, &stud[i].test2, &stud[i].test3); res[i].avg = (float) (stud[i].test1+stud[i].test2+stud[i].test3)/3; if(res[i].avg>=50 && res[i].avg<60) res[i].grade = 'D'; else if(res[i].avg>=60 && res[i].avg<70) res[i].grade = 'C';

Page 66: Cp Lab 1 Manual 2009-Srit

61

else if(res[i].avg>=70 && res[i].avg<80) res[i].grade = 'B'; else if(res[i].avg>=80 && res[i].avg <=100) res[i].grade = 'A'; else res[i].grade = 'F'; } // end for printf("\n** Printing from structure and union **\n"); printf("\n Name Reg No. Test 1 Test 2 Test 3 Average Grade\n"); for(i=0; i<no; i++) { printf("\n%s \t %s\t\t %d \t %d \t %d", stud[i].name, stud[i].regno, stud[i].test1, stud[i].test2, stud[i].test3); /* printing from union */ printf("\t %.2f \t %c", res[i].avg, res[i].grade); } printf("\n"); } // end main function OUTPUT Enter number of students:3 -- Enter details of student 1-- Enter name: Max Enter regno: CS01 Enter 3 test marks: 45 68 95 -- Enter details of student 2-- Enter name: Dan Enter regno: CS02 Enter 3 test marks: 45 86 54 -- Enter details of student 3-- Enter name: Maria Enter regno: CS03 Enter 3 test marks: 77 85 56 ** Printing from structure and union ** Name Reg No. Test 1 Test 2 Test 3 Average Grade Max CS01 45 68 95 69.33 C Dan CS02 45 86 54 61.67 C Maria CS03 77 85 56 72.67 B RESULT Thus, program to store student details using structures and unions is executed and output is verified.

Page 67: Cp Lab 1 Manual 2009-Srit

62

EX. NO. : 12

C PROGRAMMING FUNCTIONS

AIM To write a program to use function for a simple calculator. ALGORITHM Step 1: Start the program Step 2: Read the value of x. Step 3: Display menu Step 4: Use switch case statements to call functions corresponding to the menu item. Step 5: Perform operation in each function and display result Step 6: Stop the program. PSEDOCODE BEGIN READ value of x REPEAT DISPLAY menu GET choice IF choice is 1

CALL square function DETERMINE square of x = x*x PRINT value of square. IF choice is 2

CALL cube function DETERMINE cube of x = pow(x, 3)

PRINT value of cube IF choice is 3

CALL root function DETERMINE root of x = sqrt(x) PRINT value of root

IF choice is 4

EXIT UNTIL choice is 4 END

Page 68: Cp Lab 1 Manual 2009-Srit

FLOWCHART

square = x*x

cube = pow(x,3)

root = sqrt(x)

Start

Read x

Display Menu

If choice =1

Read choice

Print square

If choice =2

Print cube

If choice =3

Print root

If choice =4

Stop

63

Page 69: Cp Lab 1 Manual 2009-Srit

64

PROGRAM #include <stdio.h> #include <math.h> /* function Declarations */ void square(int); void cube(int); void root(int); main(){ int choice; int x; printf("Enter value of x:"); scanf("%d", &x); printf("\n ** MENU **"); printf("\n[1] Square"); printf("\n[2] Cube"); printf("\n[3] Square root"); printf("\n[4] Exit"); input: printf("\n-- Enter choice: "); scanf("%d", &choice); switch(choice) { case 1: square(x);/* function call */ break; case 2: cube(x); break; case 3: root(x); break; case 4: exit(1); default: printf("Invalid Choice"); goto input; break; }// end switch goto input; } // end main

Page 70: Cp Lab 1 Manual 2009-Srit

65

void square(int x){ printf("x square = %d", x*x); } // end function square. void cube(int x){ int cubeVal; cubeVal = pow(x, 3); printf("x cube = %d", cubeVal); } // end function cube void root(int x){ float sqVal; if(x<0) printf("enter positive value!"); else { sqVal = sqrt(x); printf("Square root of x: %.2f", sqVal); } // end else }// end function root. OUTPUT Enter value of x: 5 ** MENU ** [1] Square [2] Cube [3] Square root [4] Exit -- Enter choice: 1 x square = 25 -- Enter choice: 2 x cube = 125 -- Enter choice: 3 Square root of x: 2.24 -- Enter choice: 4 RESULT Thus, program to use C functions for simple calculator is executed and output is verified.

Page 71: Cp Lab 1 Manual 2009-Srit

66

REFERENCES ]

“Tutorials for OpenOffice”, http://www.tutorialsforopenoffice.org/, Accessed on: 13-9-

2009

“OpenOffice.org Tutorials”, http://documentation.openoffice.org/tutorials/index.html,

accessed on: 13-9-2009

Kamthane, n. Ashok, “Computer Programming”, ITL Education Solutions Limited,

2009

Balagurusamy, E. “Computing Fundamentals and C Programming, 1e, Tata McGraw

Hill