Beruflich Dokumente
Kultur Dokumente
COIMBATORE-10
SEMESTER I
2009-2010
Prepared by
Ms.K.Vidya, Lecturer, IT
ii
List of Experiments
a) WORD PROCESSING
b) SPREADSHEET
SIMPLE C PROGRAMMING
iii
CONTENTS
S.No Name of Experiment Page No.
List of Experiments iii
Table of Contents iv
WORD PROCESSING *
DOCUMENT CREATION, TEXT MANIPULATION 1
1 WITH SCIENTIFIC NOTATIONS
Lab 1 - Sample output 5
2 TABLE CREATION, TABLE FORMATTING AND 6
CONVERSION
Lab 2 – Sample output 8
3 MAIL MERGE AND LETTER PREPARATION 9
Lab 3 – Sample output 11
4 DRAWING – FLOWCHART 15
Lab 4 – Sample output 17
SPREADSHEET *
5 LINE, XY, BAR and PIE 19
Lab 5 – Sample output 21
6 FORMULA EDITOR 25
Lab 6 – Sample output 28
7 INCLUSION OF OBJECT, PICTURE AND 31
GRAPHICS, PROTECTING THE DOCUMENT AND
SHEET
8 SORTING AND IMPORT / EXPORT FEATURES 33
Lab 8 – Sample output 35
iv
C PROGRAMMING
9 DATA TYPES, EXPRESSION EVALUATION AND
CONDITION STATEMENTS
A. AREA AND CIRCUMFERENCE OF CIRCLE 36
B. FACTORIAL OF A GIVEN NUMBER 38
C. GENERATING FIBONACCI SERIES 40
D. CHECK WHETHER A GIVEN NUMBER IS EVEN OR 43
ODD
E. AREA OF TRIANGLE 45
F. FINDING DISCRIMINANT OF QUADRATIC 47
EQUATION
G. PAYBILL CALCULATION USING SWITCH CASE 48
STATEMENT
H. C PROGRAM TO CALCULATE SIMPLE INTEREST 50
10 ARRAYS
A. SUM AND AVERAGE OF NUMBERS IN 51
ARRAY
B. DYNAMIC INITIALIZATION OF ARRAY 53
DURING RUNTIME
C. SORT ARRAY ASCENDING AND 55
DESCENDING
D. MULTIPLICATION TABLE USING 2D ARRAY 57
v
EX. NO. : 1
WORD PROCESSING
DOCUMENT CREATION, TEXT MANIPULATION WITH
SCIENTIFIC NOTATIONS
AIM
ALGORITHM
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.
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
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'.
CTRL-1
CTRL-5
CTRL-2
CTRL-0
b b2 4 ac
Type the following formula
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
SAMPLE OUTPUT
BRAND NAME:CITIZEN
CASE 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
2 2
H2O A +B
b b2 4ac
2a
5
EX. NO. : 2
WORD PROCESSING
TABLE CREATION, TABLE FORMATTING AND
CONVERSION
AIM
ALGORITHM
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.
7
SAMPLE OUTPUT
Part A: Table Creation and formatting
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday HOLIDAY
MY MARKS
Subject Marks
Chemistry 95
Maths 50
Physics 85
Total 230
Percentage 46.00%
8
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.
9
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”.
10
SAMPLE OUTPUT
Dear Candidate,
PRINCIPAL
To,
<First Name> <Last Name>,
<Street>,
<City>,
<State>, <Zip Code>
11
12
Part D: Mailing Label
13
Part E: Creation of Envelope
14
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.
15
7. To group, select all objects by holding Shift button and clicking on the object. Go to
Format->Group->Group.
16
SAMPLE OUTPUT
Enter Account
Number, pincode
Validate account
No
Is Valid?
Yes
Enter Withdrawal
amount
Balance > No
Withdrawal
Yes
Print Insufficient
Balance
Dispense cash
Print receipt
End
17
Part B: Flow Chart - To check whether a given number is even or odd.
Start
Enter a number
Divide number
by 2
Yes No
Is remainder 0?
End
18
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.
19
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).
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 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).
20
SAMPLE OUTPUT
30 30 29 30 30 30
25 26
25 25 25 26
25 25
24 24 24
23
20 Morning
15 Afternoon
Evening
10
5
0
Sat Sun Mon Tue Wed Thu Friday
Days of the Week
21
Part B: Bar Chart
No. of
Month visitors
January 150
February 300
March 250
OUTPUT
350
300 250
300
250 ch
ar
No. of Visiters
250 M
Month
200 300
150 y
150 ar
bru
100 Fe
150
50 ry
nua
0 Ja
January February March 0 100 200 300 400
No. of Visiters
Month
800 700
700 600 600
600
No. of Visitors
500
500 No. of adult
Visitors
400 300 No. of Child
300 200 visitors
200
100
0
May June July
Month
22
Part C:Pie Chart
Importing Quantity of
Country 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
Other
Russia
countries
21% UK
Russia
UAE
Saudi Arabia 17%
3% USA
Kazakhstan
Australia UK
Pakistan 3% Iran
16%
3% Germany
Germany Pakistan
UAE
4% Iran Australia
15%
5% Kazakhstan USA Saudi Arabia
6% 7%
Other countries
23
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
9002000
7002000
6002000
5002000
Transistors
4002000
Intel Pentium
3002000
2002000
Intel 486
1002000
Intel 386
4004
80088080 8086 Intel 286
2000
70 75 80 85 90 95 00
19 19 19 19 19 19 20
Year of Introduction
24
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
25
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.
Logical Functions
26
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.
27
SAMPLE OUTPUT
Part A: Entering Formula, Auditing and Error Codes
Test
First Name Last Name Full Name 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
28
Syntax of formulas used:
sin =SIN(RADIANS(B2))
cos =COS(RADIANS(B2))
tan = TAN(RADIANS(B2))
sin
1.5
0.5
0 sin
0 30 60 90 120 150 180 210 240 270 300 330 360
-0.5
-1
-1.5
CONVERSION FUNCTIONS
Conversion Number Answer
Decimal to Binary 29 11101
Decimal to Octal 952 1670
Decimal to Hexadecimal 872 368
Binary to decimal 1100000 96
Syntax of formulas used:
=DEC2BIN(B2)
=DEC2OCT(B3)
=DEC2HEX(B4)
=BIN2DEC(B5)
LOGICAL FUNCTIONS
29
TEXT FUNCTIONS
30
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.
32
EX. NO. : 8
SPREADSHEET
SORTING AND IMPORT / EXPORT FEATURES
AIM
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
33
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.
34
SAMPLE OUTPUT
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
35
EX. NO. : 9
C PROGRAMMING
DATA TYPES, EXPRESSION EVALUATION AND CONDITION STATEMENTS
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
36
FLOWCHART
Start
Read 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
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
38
FLOWCHART
Start
Read number
fact= fact * i
i++
Yes
Is i <= num
No
Print factorial
Stop
PROGRAM
#include <stdio.h>
int main() {
int i=1, fact=1;
int num;
OUTPUT
Enter a number: 5
Factorial: 120
RESULT
Thus, program to find factorial of given number is executed and output is verified.
39
GENERATING FIBONACCI SERIES
AIM
To write a program to generate Fibonacci series up to a given number.
ALGORITHM
Step 1: Start the program.
Step 2: Enter the limit
Step 3: Check whether the number is zero or not. If zero print zero, exit.
Step 4: Set loop up to given number.
Step 5: Calulate fib= fib + a, set a=b and b=c for every iteration in the loop.
Step 6: Print the Fibonacci number in every iteration of the loop.
Step 7: Stop the program.
PSEUDOCODE
BEGIN
DECLARE lim, a, b
INITIALIZE a=0, b=1, lim=1
fib = a + b
READ num
IF num == 0
PRINT 0
REPEAT
a=b
b= fib
fib = a + b
INCREMENT lim
PRINT fib
UNTIL lim < num
END
40
FLOWCHART
Start
a=0, b=1
fib = a+b
Read number
Yes
Is num == 0 Print 0
No
a=b;
b=fib;
fib = a+b;
lim++; Yes
Print fib
No
Stop
PROGRAM
#include <stdio.h>
int main() {
int fib=1;
int a=0, b=1;
int num, i=0;
int lim =0;
fib =a+b;
OUTPUT
RESULT
Thus, program to generate Fibonacci series is generated and output is verified.
42
CHECK WHETHER A GIVEN NUMBER IS EVEN OR ODD
AIM
To write a program to find out whether a given number is even or odd.
ALGORITHM
Step 1: Start the Program.
Step 2: Enter integer value.
Step 3: Determine rem = value modulo 2.
Step 4: Check if rem is 0.
Step 5: If rem is 0, print the given value is even.
Step 6: If rem is not 0, print the given value is odd.
Step 7: End.
PSEUDOCODE
BEGIN
DECLARE rem
READ val
DETERMINE rem = val%2
IF rem == 0
PRINT Value is Even
ELSE
PRINT Value is ODD
END
43
FLOWCHART
Start
Enter value
rem = val % 2
Is rem == 0
Stop
PROGRAM:
#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.
44
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);
}
45
FLOWCHART
Start
Read a,b,c
Read s,d,area
s = (a+b+c)/2
d=(s*(s-a)*(s-b)*(s-c))
Print area
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
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.
47
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
PROGRAM
48
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.
49
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
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.
50
EX. NO. : 10
C PROGRAMMING
ARRAYS
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
51
PROGRAM
#include<stdio.h>
#define N 5
int main() {
return 0;
}
OUTPUT
Before Sorting: 10 2 5 1 25
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.
52
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
53
PROGRAM
#include <stdio.h>
int main() {
int arr[100];
OUTPUT
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.
54
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
55
PRINT max Num AS arr[N-1]
PRINT minNum AS arr[0]
END
PROGRAM
#include<stdio.h>
#define N 5
int main() {
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.
56
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
57
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");
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.
58
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
59
SET grade AS A
ELSE
SET grade AS F
INCREMENT i by 1
UNTIL i<no
#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;
60
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");
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
RESULT
Thus, program to store student details using structures and unions is executed and
output is verified.
61
EX. NO. : 12
C PROGRAMMING
FUNCTIONS
ALGORITHM
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
62
FLOWCHART
Start
Read x
Display Menu
Read choice
square = x*x
If choice =1
Print square
cube = pow(x,3)
If choice =2
Print cube
root = sqrt(x)
If choice =3
Print root
If choice =4
Stop
63
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);
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;
goto input;
} // end main
64
void square(int x){
printf("x square = %d", x*x);
} // end function square.
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.
65
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
66