Anda di halaman 1dari 72

GE 2115

COMPUTER
PRACTICE LAB - I

SARASWATHI VELU COLLEGE OF


ENGINEERING
DEPARTMENT OF COMPUTER SCIENCE &
ENGINEERING

GE 2115 - COMPUTER PRACTICE


LAB - I

LAB MANUAL
PREPARED
By

M.SENTHIL
Lect / CSE

GE 2115 - COMPUTER PRACTICE LAB - I


LIST OF EXERCISES
a) Word Processing
1.
2.
3.
4.

Document creation, Text manipulation with Scientific Notation.


Table creation, Table formatting and conversion.
Mail merge and letter preparation.
Drawing - flow chart

b) Spread Sheet
1. Chart - Line, XY, Bar and Pie.
2. Formula - formula editor.
3. Spread sheet inclusion of object, Picture and graphics, Protecting the
document and sheet.
4. Sorting and Import/Export features.
C) Simple C Programming
1.
2.
3.
4.

Data types, Expression Evaluation, Condition Statements.


Arrays.
Structures and Unions.
Functions

Microsoft
Word

Ex no: 1(a)

Document creation, Text manipulation with scientific notations


Aim:
Create an word document with the following
(i)
Text Alignment
(ii)
Adding bullets & Numbering
(iii) Line spacing
(iv) Changing the font types & size, changing text in to different cases
(v)
Using header & footer in the document
(vi) Inserting symbols & pictures
(vii) To add the animation to the text
Procedure:
(i)

Text Alignment
1. Select the text for alignment
2. For left alignment press CTRL+L (or) press align left button on
the formatting toolbar
3. For right alignment press CTRL+R (or) press align right button
on the formatting toolbar
4. For center alignment press CTRL+E (or) press align center
button on the formatting toolbar
5. For justify press CTRL+J (or) press align justify button on the
formatting toolbar

(ii)

Adding bullets & Numbering


1. Select the text where you want to add bullets & Numberings
2. Click bullets button on the formatting tool bar (or) choose
bullets & numberings option from the format menu. It shows
bullets & numberings dialogue box
3. From that box choose required bullet from the bullet tab
4. Choose numbering button on the formatting tool bar (or)
choose required numbers option from the numbered tab in the
bullets & numberings dialogue box

(iii)

Line spacing
1. Select the paragraphs of the document using the left mouse
button (or) choose select all option from the edit menu (or) by
pressing CTRL+A
2. Choose paragraph option from the format menu. A paragraph
dialogue box appears

3. Select the 1.5 lines from the line spacing list box. Then click
OK
4. Now the 1.5 line spacing is applied to the selected paragraph
(iv)

Changing the font types & size, changing text in to different


cases
For font type & size
1.
2.
3.
4.

Select the text you want to change for font types & sizes
Then choose font option from the format menu
It shows the font dialogue box
From that choose required font type from the font list box & the
required size from the size list box on the font dialogue box,
Then click OK

For changing text in to different cases


1. Select the text you want to change
2. Then choose the change case option from format menu
3. It shows change case dialogue box
5. You can choose different cases for the selected text
(v)

Using header & footer in the document


1. Open a new document
2. To enter a header that repeats on all pages in your document
choose view-> header and footer
3. Now the document is changed to the view, in which the cursor
is located at the headers pane
4. Enter the header name
5. Move the cursor to footer pane, enter footer name

(vi)

Inserting symbols & pictures

For symbols
1. Type the text, then put the cursor where you want to add the
symbol
2. Choose symbols option from the insert menu
3. Shows the symbols dialogue box
4. Then choose required symbol from the symbols dialogue box.
Then click insert

For pictures
1. Click insert->picture->clipart
2. Select the clip from the insert clipart dialogue box, which you
want to insert & click OK.
3. Now the selected clip is inserted into your document
(vii)

To add the animation to the text


1.
2.
3.
4.
5.
6.
7.

Type the text in the document


Select the text to which you want to add animation
Choose format->font option
It shows the font dialogue box, choose text effect
It shows the different animation type
Choose required one, then click OK.
Now the text that is selected is shown in animation style

Result:
Thus the word document was created & performs above operations
successfully.

Ex no: 1(b)

Document creation, Text manipulation with scientific


notations
Aim:
Prepare a word document with the following
(i)
(ii)
(iii)

Equation with scientific notation


Create a curriculum vitae of a B.E graduate
Design a visiting card

Procedure:
(i)

Equation with scientific notation

1. Enter the equation in the document


2. Select the character, which you want to show as a subscript
3. For subscript, choose the font option from the format menu, then enable
subscript check box from the font dialogue box
4. For superscript, choose the font option from the format menu, then enable
superscript check box from the font dialogue box
(ii)

Create curriculum vitae of a B.E graduate

1. Open a new document


2. Choose file->page setup option and set margins, paper size
3. Enter the given data about B.E graduate with name, age, fathers name,
experience, computer skills, and other details
4. Save your file
(iii)

Design a visiting card

1.
2.
3.
4.

Open a new document


Click on page setup option from the file menu
Click paper size tab, set the width & height & click OK
Position the cursor & click format->font & select the appropriate font
type & size
5. Enter the given details such as name, phone no, e-mail, website.

OUTPUT:
(i)

Equations

Ca(HCO3)2 -> CaCo3+Co2+H2o


(A+B)2 = A2+B2+2AB
RESUME
Name
Fathers Name
D.O.B
Sex
Martial details
Address

Raja S
Siva
14/12/1982
Male
Single
12, Anna nagar
Chennai
B.E(CSE)

Qualification
Educational details
Class/degree

Institution name

S.S.L.C

St. joseph matriculation


school vellore
St. joseph higher sec.
school vellore
S.V.C.O.E sholinghur
vellore

H.S.C
B.E

Year of
passing
March
1998
March
2000
2000-2004

Languages known
Tamil, English, Telugu
Computer skills
Ms office
C, C++, Java, VB, oracle
Experience
Working as software engineer in TCS for 2
years in Chennai
Working as software engineer in CTS for 1
year in Chennai
Date :
Place :

Candidate Sign

10

Percentage of
mark
75%
80%
84%

VISITING CARD

V. Ramesh Babu
Managing Director
Mobile: 9756453212

VRB PUBLISHERS
24, Anna nagar, Chennai
E-mail: vrbpub@hotmail.com
Website:www.vrbpub.com

Result:
Thus the word document was created with Equation, Bio data & visiting
card.

11

Exno:2 (a)

Table creation, Table formatting & conversion


Aim:
a) Create a table with the following columns & display the students
results
(i)
(ii)
(iii)
(iv)

name, rollno, sub1, sub2, sub3, ,sub5 total, average.


Sort all students in ascending order with the name as the key
Calculate total marks & Average of all students
Find the maximum, minimum average mark

Procedure:
For table creation
1.
2.
3.
4.
5.

Choose Table insert Table option


It display the insert table dialogue box
Choose required columns & rows
Click OK to add table in your document
Enter the columns name, rollno, 5 subjects, total,
average
6. Enter the text in the columns by pressing tab key
For sorting
1.
2.
3.
4.

Consider the above table


Place the cursor in the table and click TableInsert
It displays the sort dialogue box
In the sort by option select name from the drop down
list & select ascending option, & click OK

For total calculation


1. Consider the above table
2. Place the cursor in the total of second row. Click
TableFormula. It display a formula dialogue box with
formula =SUM(LEFT).
3. Click OK.
4. In the same way of finding total in the remaining rows

12

For average calculation


1. Consider the above table
2. Place the cursor in the total of second row. Click
TableFormula. It display a formula dialogue box with
formula =AVERAGE(LEFT).
3. Click OK.
4. In the same way of finding average in the remaining
rows
For maximum mark
1. Consider the above table
2. Place the cursor in the total of second row. Click
TableFormula. It display a formula dialogue box with
formula =MAX(LEFT).
3. Click OK.
4. In the same way of finding average in the remaining
rows
For minimum mark
1. Consider the above table
2. Place the cursor in the total of second row. Click
TableFormula. It display a formula dialogue box with
formula =MIN(LEFT).
3. Click OK.
4. In the same way of finding average in the remaining
rows

13

OUTPUT:
For total
Rno
10
20
30

Name
Raja
Rani
suji

Sub1
78
90
56

Sub2
23
45
67

Sub3
77
89
45

Sub4
66
78
97

Sub5
45
34
77

Total
289
336
342

Sub1
78
90
56

Sub2
23
45
67

Sub3
77
89
45

Sub4
66
78
97

Sub5
45
34
77

Average
57.8
67.2
68.4

Sub2
23
45
67

Sub3
77
89
45

Sub4
66
78
97

Sub5
45
34
77

Maximum
78
90
97

Sub2
23
45
67

Sub3
77
89
45

Sub4
66
78
97

Sub5
45
34
77

Minimum
23
34
45

For average
Rno
10
20
30

Name
Raja
Rani
Suji

For maximum mark


Rno
10
20
30

Name
Raja
Rani
suji

Sub1
78
90
56

For minimum mark


Rno
10
20
30

Name
Raja
Rani
suji

Sub1
78
90
56

Consider previous table - After sorting based on sub1 column [ascending


order]
Rno
30
10
20

Name
suji
Raja
Rani

Sub1
56
78
90

Sub2
67
23
45

Sub3
45
77
89

Sub4
97
66
78

Sub5
77
45
34

Minimum
45
23
34

Result:
Thus the table was created & calculates the total, average, maximum &
minimum marks of the students.

14

Ex no:2 (b)

Table creation, Table formatting & conversion


Aim:
Design a suitable table with the following
(i) Write a step to split a cell & merge 2 cells in a table
(ii) Write the step to convert table to the text
(iii) Write the step to convert text to the table
(iv) Write the step to split the single table to two table
Procedure:
(i) Write a step to split a cell & merge 2 cells in a table
For merge 2 cells
1. Create table using table menu
2. Select the cells for merging in a table
3. Select the merge cell option from the table menu, or click on
merge cells button in the tables & borders toolbar
4. Click left mouse button & the selected cells will become one
cell
For split a cell
1. Select a cell in a table by clicking on it
2. Click table menu from the menu bar
3. Select split cell option from the table menu, it shows dialogue
box
4. Enter your choice to split cells and click OK
(ii) Write the step to convert table to the text
1.
2.
3.
4.
5.

Select a table in a document


Choose the covert table to text options from the table menu
Now it shows the convert table to text dialogue box
Choose the separator of the text. Then click OK
Now, the table information is converted into text in a
document

15

(iii) Write the step to convert text to the table


1 Select the text in the document
2 Choose the convert text to table option from the
table menu
3 Now it shows the convert text to table dialogue box
4 Choose the table size & separator text option. Then
click OK
5 Now, the text information is converted into text into
a table
(iv) Write the step to split the single table to two table
1. Select the row from which the table is to be divided
2. Choose split table option from the table menu,
click on it
3. Now the table split into 2 tables

16

OUTPUT:
Before splitting (cell)
Name
Suresh
Ramesh

Age
24
22

Degree
BSC
BE

After splitting (cell) [3rd column of 1st row has splitted with 2 cells]
Name
Suresh
Ramesh

Age
24
22

Degree
BSC
BE

Age
24
22

Degree
BSC
BE

Before merging (cell)


Name
Suresh
Ramesh

After merging (cell) [2nd, 3rd column of 2nd row has joined with single cell]
Name
Suresh
Ramesh

Age
24
BSC
22

Degree
BE

Before conversion [table to text]


Name
Suresh
Ramesh

Age
24
22

Degree
BSC
BE

After conversion [table to text]


Name
Suresh
Ramesh

Age
24
22

Degree
BSC
BE

17

Before conversion [text to table]


Name
Suresh
Ramesh

Age
24
22

Degree
BSC
BE

After conversion [text to table]


Name
Suresh
Ramesh

Age
24
22

Degree
BSC
BE

Age
24
22
20

Degree
BSC
BE
MCA

Name
Suresh

Age
24

Degree
BSC

Ramesh
Raju

22
20

BE
MCA

Before splitting (table)


Name
Suresh
Ramesh
Raju
After splitting (table)

Result:
Thus the table was created & perform all operations successfully

18

Ex no: 3

Mail merge & Letter Preparation


Aim:
(i) Use mail merge to create letters for 5 persons.
(ii) Create & print the envelops for the address given below.
Procedure:
(i) Use mail merge to create letters for 5 persons.
Creating the main document
1. Open a new document.
2. Type the contents.
3. Place the cursor where you want print the address.
4. From the tools menu select Letters and Mailing then select mail
merge.
5. It shows the mail merge dialogue box at the right side of the
window.

6.
7.

Select what type of document are you working on?


Click Starting document

19

8. Select the starting document from the following 3 documents.


Use the current document
Start from a template
Start from existing document
9. Select Use the current document

10. Then click Next: Select recipients

20

11. It will display all the recipients, In that select Type a new list

12. Then click Create, it will display the New Address List dialog box.

13. Enter the Address Information for more than 2 persons, then click
close.
21

14. Save the mail merge with the appropriate name.

15. It will display all the peoples information. Here we can also add or
delete or we can update the information.

22

16. Select Address Block

17. Click Write your letter

23

18. Select Next: Preview your letters

19. Select Complete the merge

24

20. Select Edit individual letters

Result :
Thus the mail merge method was used to produce letters for each person
successfully.

25

Ex no: 4

Drawing a flowchart
Aim:
(i)
(ii)
(ii)

Draw the basic flowchart symbols & name them in


the document
Draw a flowchart for the expression
A=b+c*d/e
Draw a flowchart to judge a student get first, or
second, or third class by taking student marks as
input

Procedure:
(i) Draw the basic flowchart symbols & name them in the document
1. Choose the flowchart option in the auto shapes menu of
the drawing tool bar
2. Choose the appropriate flowchart symbol & drag the
symbol in the document
3. Type the text in the symbol, by right click, then choose
add text option
Flow lines

Terminal symbol start/end (oval symbol)

Input/output symbol (parallelogram)

26

Process symbol (Rectangle)

Decision symbol (diamond)

Connectors

a
a

(ii) Draw a flowchart for the expression


A=b+c*d/e
1. Choose the flowchart option in the auto shapes menu of the drawing tool bar
2. Choose the flowchart symbols & drag the symbol in the document
3. Type the text in the symbol, by right click, then choose add text option

27

OUTPUT:

Start

Read
b,c,d,e

A=b+c*e/d

Print A

Stop

28

Start

Read m1 to
m5

Total=
m1+m2+m3+m4+m5

Avg=total/5

yes
Distinction

If
avg>=75

no
yes
If ((avg<75)&&
(avg>=60))

First class

no
yes

If ((avg<60)&&
(avg>=50))

Second
class

yes

no
yes

If ((avg<50)&&
(avg>=35))

Third class

no
print fail

Stop
29

Result:
Thus the flowchart was created & verified successfully

30

MS
EXCEL

31

Ex no:5

Chart-Line, XY, Bar and Pie


Aim:
Draw the following charts for the analysis of student mark MS Excel
spread sheet
(i)
(ii)
(iii)
(iv)

Line chart
XY chart
Bar chart
Pie chart

Procedure:
For Line chart
1. Enter the data about student in the worksheet
2. Choose chart option from the insert menu (or) choose the chat
wizard button from the standard tool bar
3. It shows the chart wizard dialogue box
4. From that choose the chart type as line
5. Click next button on the dialogue box & enter the details
6. Then click finish button
For XY chart
(i) Enter the data about student in the worksheet
(ii) Choose chart option from the insert menu (or) choose the
chart wizard button from the standard tool bar
(iii) It shows the chart wizard dialogue box
(iv) From that choose the chart type as XY(Scatter)
(v) Click next button on the dialogue box & enter the details
Then click finish button
For Bar chart
(i) Enter the data about student in the worksheet
(ii) Choose chart option from the insert menu (or) choose
chart wizard button from the standard tool bar
(iii) It shows the chart wizard dialogue box
(iv) From that choose the chart type as Bar
(v) Click next button on the dialogue box & enter the
details
(vi) Then click finish button

32

the

For Pie chart


(i)
(ii)
(iii)
(iv)
(v)

Enter the data about student in the worksheet


Choose chart option from the insert menu (or) choose the
chart wizard button from the standard tool bar
It shows the chart wizard dialogue box
From that choose the chart type as Pie
Click next button on the dialogue box & enter the details
Then click finish button

Output for line chart


Given datas are

33

Output for XY chart


Given datas are

34

For Bar chart given datas are

35

For pie chart

Result:
Thus the charts are created for the student mark analysis.

36

Ex no:6

Formula Editor
Aim:
To create a suitable examination database & find the sum of the marks of
each student & the respective classes secured by the students
Rules
(i)
Pass if marks in each subject >=35
(ii)
Fail if marks in each subject <35
(iii) Distinction if average >=75
(iv) First class if average >=60 but less than 75
(v)
Second class if average >=50 but less than 60
(vi) Third class if average >=35 but less than 50
Display average marks of the class subject wise & pass percentages
Procedure:
1.
2.
3.
4.

Enter the student name, three marks


Place the cursor in capital E2, type =sum(b2:d2)
Place the cursor in capital F2, type =average(b2:d2)
Click on G2, type
=if(or(b2<35,c2<35,d2<35)fail,if(f2>=75,distinction,
if(f2>=60,first class, if(f2>=50,second class, third class))))
5. Copy the formula to the remaining students
6. Finally, the worksheet displayed with suitable students examination
database

37

OUTPUT:

Result:
Thus the suitable examination database & the sum of the marks of each
student are displayed in the worksheet

38

Exno:7

Spread sheet inclusion of object, pictures & graphics, protecting the


document & sheets
Aim:
To insert an object, pictures with 3D effects
Procedure:
For object insertion
1. Choose one of the object (clip art) to insert into the worksheet
2. Choose objects option in the insert menu insert->picture->clipart
3. Choose appropriate object from the auto shape menu of the drawing
tool bar
For object insertion
1.
2.
3.
4.
5.
6.

Choose picture from the insert menu


Choose objects option in the insert menu insert->picture->from file
Now the insert picture dialogue box is shown
Navigate & choose the picture to insert into the worksheet
Then click insert button
Now the selected picture is inserted into the worksheet

Worksheet with 3D effects


1.
2.
3.
4.
5.
6.
7.

Open the worksheet using file->open option


Now it opens the selected worksheet
Select the data range in the worksheet
Now choose format->auto format
Now it shows the auto format dialogue box
From that click on the 3D effects auto format
Now the worksheet is shown in 3D format style

Protect a sheet in MS Excel


1. Click on cell which u want to protect
2. Choose tools->protection, then choose protect sheet, it shows the
protect sheet dialogue box asking the password to protect sheet
3. Type the password click & OK. Then it asks for confirmation
password box, type same password again then click OK
4. Now the sheet is under protection
5. If u click on any cell to type, then the following message box appears
by specifying the sheets under protection
39

6. To remove protection, choose tools-> protection->unprotect sheet,


then type password to unprotect
7. Now the sheet can be unprotect
Protecting the workbook
1 Open the work book to protect
2 Choose tools->protection, then choose protect work book, it shows the
protect work book dialogue box asking the password to protect sheet
3 Type the password click & OK. Then it asks for confirmation password
box, type same password again then click OK
4 Now the workbook is under protection
5 If you click on any cell to type, then the following message box
appears by specifying the sheets under protection
6 To remove protection, choose tools-> protection->unprotect sheet, then
type password to unprotect
7 Now the workbook can be unprotect

40

Result:
Thus the Excel sheet was created with pictures, protect the sheets
& book successfully

41

Ex no:8

Sorting & Import / Export Features


Aim:
(i)

Enter the following data into the worksheet using data>form command

Name
Raja
Anu
Suji
Banu
Kishore

Dept
Computer
Accounts
Marketing
Clerk
Engineering

Salary
12000
11000
8000
5000
24000

Sort the data by salary within the department using sort


command. Calculate the total salary of each department using Auto
Filter
(ii)Create Transport Reservation sheet with the following
description:
Passenger Name: Not to exceed 20 characters with a display of
message if it exceeds. Use the interactive display request Please
enter name.
Gender: Male/Female options to select one. Use the interactive
display request Select Gender Please
Seat Numbers: >1 and <=100 with display message if out of range.
Use the interactive display request enter seat number
Class: First or second or third to select as required. Use the
interactive display request Please select Class
Amount: If the class is First, then the amount is Rs.500, if the class
is Second, Rs.400 and if the class is third, Rs.300.

42

(ii)

Find the subtotals to a list specified below

Salesman
Babu
Suresh
Balaji
Raja
Vijay

Product
Keyboard
Cpu
Moniter
CD
Hard disk

Sales
1000
3000
1500
15
800

Procedure:
(i)
1.
2.
3.
4.

Enter the name, department, salary in different columns


Click data->form option, it shows the form window
Click new button in the form to add the rows to the list
After adding the rows, place the cursor in the list in the work
sheet
5. Click data->sort, it show the sort dialogue box
6. From that Select sort by option & select dept, click OK
7. Again in sort, click salary from Then by drop down list
8. The row are sorted now, depending on the dept & salary
9. Click Data->Filter->AutoFilter, it shows an arrow at each field
10. On the dept click the icon select account
11. The list of rows which belongs to account is displayed
12. In the same way of find each dept total salary
(ii)Create Transport Reservation sheet with the following
description:
1. Click on A5, enter the passenger name
2. Click C5, choose data->validation
3. It shows data validation dialogue box
4. Click on setting tab
5. Select the text length from Allow drop down list
6. Select less than or equal to from data list box
7. Type 20 in maximum box
8. Click input message tab, in that, type please enter name
9. Click the error alert tab, select stop from style
10. In the error message box type, Not to exceed 20 characters
11. Then click OK
12. Click on A7, Enter Gender
13. Click C7, choose data->validation

43

14. Click settings tab, select list from allow drop down list
15. Type male, female in the source box
16. Click input message tab, in that type select gender please,
then click OK
17. Click on A9, Enter seat number
18. Click C9, click data->validation
19. Click settings tab, select whole numbers from allow drop down
list, between from data, 1 in minimum & 100 in maximum
20. Click input message tab, in that type Enter seat number
21. Select stop from style, in the error message box type. number
selected is out of range, then click OK
22. Click on A11, Enter Class
23. Click C11, choose data->validation
24. Click settings tab, select list from allow drop down list, type
first, second, third in source
25. Click input message tab, in that type please select class, then
click OK
26. Click on A12 enter amount
27. Click C12, type =
if(C11=first,500,if(C11=second,400,300))
(iii)

Find the subtotals

1. Type the list in a work sheet with column as salesman, product,


sales
2. Select all, then sort the sales column to add subtotals
3. Clack data->subtotals
4. The subtotals dialogue box appears
5. Select the column name from At each change in drop down list
box to add sub totals
6. Use the sum function from the Use function drop down list box
7. Select the field name (sales, product) from the Add subtotals to
drop down list box
8. Click OK to add subtotals to the list
9. Now the list displays the subtotals & the grand totals

44

OUTPUT:

After sorting (based on salary)

Result:
Thus the sorting and import / export features was created successfully.

45

C PROGRAMS

46

Ex no: 9

Data types, Expression Evaluation, Condition Statements


Aim: To write a C program for the datatypes, expression evaluation and
Condition Statements.
9.1 Write a C program to find the area of a circle
Algorithm:
1.
2.
3.
4.
5.

Start
Read radius value
Give formula A=3.14*r*r
Print a
Stop

Flowchart:
start

Read r

a=3.14*r*r

Print a

Program:

stop

#include<stdio.h>
#include<conio.h>
void main()
{
int r;
float a;
clrscr();
printf("Enter the radius");
scanf("%d",&r);
47

a=3.14*r*r;
printf("Area=%f",a);
getch();
}
OUTPUT:
Enter the radius3
Area=28.260000
9.2 Write a C program to convert Celsius to Fahrenheit temperature
Aim:
1
2
3
4
5

Start
Read Celsius value
Give formula faren=(1.8*cel)+32
Print faren
Stop

Flowchart:
start

Read cel

faren=(1.8*cel)32

Print faren

Program:
stop
#include<stdio.h>
#include<conio.h>
void main()
{
float cel, faren;
clrscr();
printf("enter the celcius value");
scanf("%f",&cel);
faren=(1.8*cel)+32;

48

printf("The Farenheit value of the given %f celcius value is %f",cel,faren);


getch();
}
OUTPUT:
Enter the celcius value: 30
The Farenheit value of the given 30.000000 celcius value is 86.000000
Write a C program to evaluate SIN series
Algorithm:
1.
2.
3.
4.
5.
6.
7.
8.
9.

Start
Enter n, x value
Convert x into radius using x=x*3.1412/180
t<-x, sum<-x
Setup for loop from i<-1, until i<n increment i
t=(t*pow((double)(-1),(double)(2*i1))*x*x)/(2*i*(2*i+1));
Sum=sum+t
Print sum
Stop

Flowchart:
Start

Read x, n

Print x, n

X=x*3.142/180
T=x, sum=x

For I=1;I<n+1;I++

T=(t*pow((double)(-1),(double)
(2*I-1))*x*x)/(2*I*(2*I+1))
sum=sum+t
49

Print sum

Program:
Stop

#include<stdio.h>
#include<math.h>
#include<conio.h>
void main()
{
float x,t,sum,n;
int i;
clrscr();
printf("Enter the value of x,n :");
scanf("%f%f",&x,&n);
printf("%4.2f%f\n",x,n);
x=x*3.1412/180;
t=x;
sum=x;
for(i=1;i<n;i++)
{
t=(t*pow((double)(-1),(double)(2*i-1))*x*x)/(2*i*(2*i+1));
sum=sum+t;
}
printf("the value of SIN(X)=%6.2f\n",sum);
getch();
}
9.3 Write a C program to print the datatype values.
Program:
#include<stdio.h>/* standard input output */
#include<conio.h>/* Console input output */
void main()
{
int x=2;
float y=2.2;
char z='s';
clrscr(); /* clear the screen */
printf("%d\n%f\n%c",x,y,z);
getch();
}

50

Output:
2
s
2.200000
9.4 Write a C program to perform arithmetic operations.
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf("Enter the any two value:");
scanf("%d%d",&a,&b);
c=a+b;
printf("Sum=%d\t",c);
c=a-b;
printf("Sub=%d\t",c);
c=a*b;
printf("mul=%d\t",c);
c=a/b;
printf("Div=%d",c);
getch();
}
OUTPUT:
Enter the any two value:6
3
Sum=9
Sub=3
mul=18
Div=2
9.5 Write a C program to find the average of three numbers.
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
float a,b,c,sum,avg;
clrscr();
printf("Enter the any 3 value:");
scanf("%f%f%f",&a,&b,&c);
sum=a+b+c;
printf("Sum=%f",sum);
avg=sum/3;
printf("\nAverage=%f",avg);
getch();
}

51

OUTPUT:
Enter the any 3 value: 75
Sum=225.000000
Average=75.000000

75

75

9.6 Write a C program to swap the values of two variables without using a
third variable.
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int a=5,b=6;
clrscr();
printf("a=%d \t b=%d\n",a,b);
a=a+b;
b=a-b;
a=a-b;
printf("a=%d \t b=%d",a,b);
getch();
}
OUTPUT:
a=5 b=6
a=6 b=5
9.7 Write a C program to swap the values of two variables using a third
variable.
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int a=5,b=6,c;
clrscr();
printf("a=%d b=%d\n",a,b);
c=a;
a=b;
b=c;
printf("a=%d b=%d",a,b);
getch();
}
OUTPUT:
a=5 b=6
a=6 b=5

52

9.8 Write a C program to find the square root for the given value.
Program:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int x,y;
clrscr();
printf("Enter the value of x:");
scanf("%d",&x);
y=sqrt(x);
printf("Square root of %d is %d",x,y);
getch();
}
OUTPUT:
Enter the value of x: 81
Square root of 81 is 9
9.9 Write a C program to find the given number is Odd or Even.
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int num;
clrscr();
printf("Enter a number:");
scanf("%d",&num);
if((num%2)==0)
printf("\n The given number is a even number");
else
printf("\n The given number is a odd number");
getch();
}
OUTPUT:
Enter a number:6
The given number is a even number

53

9.10 Write a C program to find the given year is leap year or not
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int year;
clrscr();
printf("Enter a year:");
scanf("%d",&year);
if((year%4)==0)
printf("\nThe given year is a leap year");
else
printf("\nThe given year is not a leap year");
getch();
}
OUTPUT:
Enter a year: 2012
The given year is a leap year
9.11 Write a C program to find the biggest number from the given three
numbers.
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf("Enter any three number:");
scanf("%d%d%d",&a,&b,&c);
if((a>b)&&(a>c))
printf("\n%d is the biggest number",a);
else if((b>a)&&(b>c))
printf("\n%d is the biggest number",b);
else
printf("\n%d is the biggest number",c);
getch();
}
OUTPUT:
Enter any three number:5 2
3
5 is the biggest number

54

9.12 Write a C program to find the factorial of a given number.


Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int fact=1,num;
clrscr();
printf("Enter a number:");
scanf("%d",&num);
for(int i=1;i<=num;i++)
{
fact=fact*i;
}
printf("\nThe factorial of %d is %d",num,fact);
getch();
}
OUTPUT:
Enter a number:6
The factorial of 6 is 720
9.13 Write a C program to find the product of the given two number
without using * operator.
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,i,sum=0;
clrscr();
printf("Enter the values for a and b:");
scanf("%d%d",&a,&b);
for(i=1;i<=a;i++)
sum=sum+b;
printf("\nThe product of the given two number is:%d",sum);
getch();
}
OUTPUT:
Enter the values for a and b:5
2
The product of the given two number is:10

55

9.14 Write a C program to check whether the given number is prime or not.
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int i=2,num;
clrscr();
printf("Enter a number:");
scanf("%d",&num);
while(i<=num-1)
{
if((num%i)==0)
{
printf("The given number %d is not a prime",num);
exit(0);
}
i++;
}
if(i==num)
{
printf("The given number %d is a prime",num);
}
getch();
}
OUTPUT:
Enter a number:9
The given number 9 is not a prime
9.15 Write a C program to find the sum of digits of a number.
Program:
/*To find the sum of the digits of a number*/
#include<stdio.h>
#include<conio.h>
void main()
{
int num,sum=0;
clrscr();
printf("Enter a number:");
scanf("%d",&num);
while(num>0)
{
sum+=num%10;
num=num/10;
}
printf("\nThe sum of given digit is %d",sum);

56

getch();
}
OUTPUT:
Enter a number: 1234
The sum of given digit is 10
9.16 Write a C program to find the reverse the digits of a number.
Program:
/*To find the reverse the digits of a number*/
#include<stdio.h>
#include<conio.h>
void main()
{
int num,rn;
clrscr();
printf("Enter a number:");
scanf("%d",&num);
printf("\nThe reverse of the given digit is ");
while(num>0)
{
rn=num%10;
num=num/10;
printf("%d",rn);
}
getch();
}
OUTPUT:
Enter a number: 12345
The reverse of the given digit is 54321
9.17 Write a C program to find the Fibonacci series of a given number.
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,fib[20];
clrscr();
fib[0]=0;
fib[1]=1;
printf("Enter the value of n:\n");
scanf("%d",&n);
printf("The Fibonacci Series are:\n");
printf("\n%d \t%d",fib[0],fib[1]);
for(i=2;i<=n-1;i++)
{
fib[i]=fib[i-1]+fib[i-2];

57

printf("\t%d",fib[i]);
}
getch();
}

OUTPUT:
Enter the value of n: 10
The Fibonacci Series are:
0

13

21

34

9.18 Write a C program to find the sum and difference of two matrices.
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int a[3][3],b[3][3],c[3][3],d[3][3],i,j,n;
clrscr();
printf("\nEnter the size for A and B Matrix:");
scanf("%d",&n);
printf("\nEnter the values for the matrix A:");
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("\nEnter the values for the matrix B:");
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
scanf("%d",&b[i][j]);
}
}
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
c[i][j]=a[i][j]+b[i][j];
d[i][j]=a[i][j]-b[i][j];
}
}
printf("\n Matrix Addition:\n");
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
printf("\t%d",c[i][j]);
58

}
printf("\n");
}
printf("\n Matrix Subtraction:\n");
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
printf("\t%d",d[i][j]);
}
printf("\n");
}
getch();
}

OUTPUT:
Enter the size for A and B Matrix:2
Enter the values for the matrix A:1 2 3 4
Enter the values for the matrix B:4 3 2 1
Matrix Addition:
5
5
5
5
Matrix Subtraction:
-3
-1
1
3

9.19 Write a C program to find the product of two matrices.


Program:
/*Matrix Multiplication*/
#include<stdio.h>
#include<conio.h>
void main()
{
int a[3][3],b[3][3],c[3][3],i,j,n,k;
clrscr();
printf("\nEnter the size for A and B Matrix:");
scanf("%d",&n);
printf("\nEnter the values for the matrix A:");
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
scanf("%d",&a[i][j]);
}

59

}
printf("\nEnter the values for the matrix B:");
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
scanf("%d",&b[i][j]);
}
}
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
c[i][j]=0;
for(k=1;k<=n;k++)
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
}
printf("\n Matrix Multiplication:\n");
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
printf("\t%d",c[i][j]);
}
printf("\n");
}
}
OUTPUT:
Enter the size for A and B Matrix:2
Enter the values for the matrix A: 1

Enter the values for the matrix B: 2

Matrix Multiplication:
6
8
16 21

60

9.20 Write a C program to generate numbers between 1 and 100 which are
divisible by 2 and not divisible by 3 and 5.
Program
/*Generate numbers between 1 and 100 which are divisible by 2 and not
divisible by 3 and 5*/
#include<stdio.h>
#include<conio.h>
void main()
{
int i;
printf("The following numbers are divisible by 2 but not divisible by 3&5:\n");
for(i=1;i<=100;i++)
{
if(((i%2)==0)&&((i%3)!=0)&&((i%5)!=0))
{
printf("\t%d",i);
}
}
}
OUTPUT:
The following numbers are divisible by 2 but not divisible by 3&5:
2
4
8
14 16 22 26 28 32
34 38 44
46 52 56 58 62 64 68 74 76 82 86 88 92
94 98

Result:
Thus the C Program was executed successfully with data types,
expression evaluations and control statements.

61

ARRAYS
Ex.No.10
Write a C program to find the largest and smallest of the given array.
Algorithm:
1. Start
2. Declare variables a[100], i
3. Read total array elements
4. Read the elements of the array using for loop
5. if a[i]>large then large=a[i]
6. else a[i]<small small=a[i]
7. Print the largest & smallest number of given array
8. Stop
Flowchart:

start

Read array
element

For i=0;I<n;i++

Large=a[i]

If
a[i]>large
yes
no
nop
Small=a[i]
no

Print
small,large
end

62

Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int a[100],i,small,large,no;
clrscr();
printf("In how many numbers you want to find");
scanf("%d",&no);
printf("\n Enter the elements of the array");
for(i=0;i<no;i++)
scanf("%d",&a[i]);
printf("\n The elements of the array");
for(i=0;i<no;i++)
printf("\n %d",a[i]);
small=a[0];
large=a[0];
for(i=1;i<no;i++)
{
if(a[i]>large)
large=a[i];
else if(a[i]<small)
small=a[i];
}
printf("\n The largest of the given array is %d",large);
printf("\n The smallest of the given array is %d",small);
getch();
}
OUTPUT
In how many numbers you want to find5
Enter the elements of the array8 5 2 1 9
The elements of the array
8
5
2
1
9
The largest of the given array is 9
The smallest of the given array is 1

Result:
Thus the C program to find the largest and smallest of the given array was
executed successfully.

63

STRUCTURES AND UNIONS


Ex no: 11

11.1 Write a C program to print the student rollno, name, marks using
structures
Algorithm:
1. Start
2. Define the structures with members name, rno, marks
3. Declare structure variable as array s[10]
4. Enter the number of the students, name, mark, rno
5. Access structure members in main using structure variable
6. Print students details
7. Stop
Flowchart:
start

Struct stud
Name:
Mark
rno

For i=0;I<n;i++

Read name,
mark, rno

Print name,
mark, rno

end

64

Program:
#include<stdio.h>
#include<conio.h>
struct stud
{
int rollno;
char name[30];
int cp,math,eng,total;
float avg;
char grade;
}a[5];
main()
{
int i,n;
printf("Enter the number of students:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("Enter the student %d details:",i);
printf("\n RollNo:");
scanf("%d",&a[i].rollno);
printf("\n Name:");
scanf("%s",&a[i].name);
printf("\n CP:");
scanf("%d",&a[i].cp);
printf("\n math:");
scanf("%d",&a[i].math);
printf("\n English:");
scanf("%d",&a[i].eng);
a[i].total=a[i].cp+a[i].math+a[i].eng;
a[i].avg=a[i].total/3;
if(a[i].avg<40)
a[i].grade='D';
else if(a[i].avg<60)
a[i].grade='C';
else if(a[i].avg<80)
a[i].grade='B';
else
a[i].grade='A';
}
printf("\t\t Students mark details:\n");
printf("\n RollNo\tName\tCP\tMath\tEnglish\tTotal\tAverage\tGrade");
for(i=1;i<=n;i++)
printf("\n%d\t%s\t%d\t%d\t%d\t%d\t%f\t
%c",a[i].rollno,a[i].name,a[i].cp,a[i].math,a[i].eng,a[i].total,a[i].avg,a[i].grade);
}

65

OUTPUT
Enter the number of students: 2
Enter the student 1 details:
RollNo:1
Name:sen
CP:90
math:85
English:80
Enter the student 2 details:
RollNo:2
Name:kavi
CP:85
math:65
English:70
Students mark details:
RollNo Name
1
sen
2
kavi

CP
90
85

Math English Total Average Grade


85
80
255
85.000000
A
65
70
220
73.000000
B

Result:
Thus the C program to print the student rollno, name, marks using

structures was executed successfully.

66

#include<stdio.h>
#include<conio.h>
struct student
{
char name[25];
int rno;
int marks;
}s[10];
void main()
{
int i,n;
clrscr();
printf("\n Enter the number of the students");
scanf("%d",&n);
printf("\n Enter the student details");
printf("\n Enter the Rollno Name Marks");
for(i=1;i<=n;i++)
scanf("%d%s%d",&s[i].rno,&s[i].name,&s[i].marks);
printf("\n");
printf("\n Student details are \n\n");
printf("Rollno \t Name \t\t Marks\n");
for(i=1;i<=n;i++)
printf("%d\t\t%s\t\t%d\n",s[i].rno,s[i].name,s[i].marks);
getch();
}

67

11.2 Write a C program to print employee details using Union.


Program:
#include<stdio.h>
#include<conio.h>
union
{
char name[20];
int idno;
float salary;
}desc;
void main()
{
strcpy(desc.name,"vinod");
clrscr();
printf("Employee Details\n");
printf("The name is %s\n",desc.name);
printf("The idno is %d",desc.idno);
printf("The salary is %6.2f\n",desc.salary);
desc.idno=10;
printf("Employee Details\n");
printf("The name is %s\n",desc.name);
printf("The idno is %d",desc.idno);
printf("The salary is %6.2f\n",desc.salary);
desc.salary=6500.00;
printf("Employee Details\n");
printf("The name is %s\n",desc.name);
printf("The idno is %d",desc.idno);
printf("The salary is %6.2f\n",desc.salary);
getch();
}
OUTPUT:
Employee Details
The name is vinod
The idno is 26998The salary is 73784926787784641000000000000.00
Employee Details
The name is
The idno is 10The salary is 73657479561144955000000000000.00
Employee Details
The name is
The idno is 8192The salary is 6500.00

68

FUNCTIONS
Ex no: 12
12.1 Write a C program to perform arithmetic operations using function.
Algorithm:
1.
Start
2.
Declare variables a,b,c,d,e,f
3.
Declare 4 functions add(), sub(), mul(), div()
4.
To get 2 inputs a, b
5.
Call add(). It return value to c
6.
Call sub(). It returns values to d
7.
Call mul(). It returns value to e
8.
Call div(). It returns value to f
9.
Print c, d, e, f values
10.
Stop
Flowchart:
start

Read a,b

Call add()

Call sub()

Call mul()

Call div()

Print c,d,e,f

end

69

add()

Sub()

C=a+b

D=a-b

Return C

Return D

Mul()

Div()

E=a*b

F=a/b

Return E

Return F

70

Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,d,e,f;
int add(int a, int b);
int sub(int a, int b);
int mul(int a, int b);
int div(int a, int b);
clrscr();
printf("Enter 2 numbers");
scanf("%d%d",&a,&b);
c=add(a,b);
printf("Addition=%d\n",c);
d=sub(a,b);
printf("Subtraction=%d\n",d);
e=mul(a,b);
printf("Multiplication=%d\n",e);
f=div(a,b);
printf("Division=%d",f);
getch();
}
int add(int a, int b)
{
int z;
z=a+b;
return z;
}
int sub(int a, int b)
{
int z;
z=a-b;
return z;
}
int mul(int a, int b)
{
int z;
z=a*b;
return z;
}
int div(int a, int b)
{
int z;
z=a/b;
return z; }

71

OUTPUT:
Enter 2 numbers: 8
2
Addition=10
Subtraction=6
Multiplication=16
Division=4
12.2 Write a C program to find the factorial of a given number using
recursive function.
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int n;
long int fact();
clrscr();
printf("Enter the number:");
scanf("%d",&n);
printf("\nThe factorial of the given number %d is %ld",n,fact(n));
getch();
}
long int fact(int n)
{
if(n==0)
return(1);
else
return(n*fact(n-1));
}
OUTPUT:
Enter the number:5
The factorial of the given number 5 is 120

Result
Thus the C program to perform Addition, Subtraction, Multiplication, and
Division using function is executed successfully

72

Anda mungkin juga menyukai