[go: up one dir, main page]

0% found this document useful (0 votes)
329 views114 pages

FOC Lab Manual

Download as doc, pdf, or txt
Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1/ 114

COMPUTER PRACTICE LAB - I

INTRODUCTION TO MS-WORD
OBJECTIVES:
1. To expose the students about the Graphical User Interface in Windows Operating Systems.
2. Understanding about word processors and learn, how to prepare documents by using
Microsoft Word.
PRELIMINARY EXPLANATIONS:
Nowadays, the Windows X Operating System is the most popular operating systems
for PCs. Example: Windows 95, Windows 98, Windows 2000 and Windows XP. One of the
most important reasons of this popularity is they are having rich in Graphical User Interface
(GUI) support. GUI makes the people easy to interact with the system. GUI has menus, dialog
boxes, icons, etc, which allows the users to work easy with the system because people
recognize and respond to graphic representations of concepts much more readily than if they
have to read and write word.
As the Windows Operation Systems have GUI, applications written for them have
very good graphical interfaces, compared with the older applications written in the time of
non-GUI operating systems like MS-DOS. Nowadays any person in a modern society, without
having to have job related with computers, is, and should be, able to use many different
applications on PCs. These applications include word processors, spreadsheets, etc.
Word Processors
Word processor is an application program which is used for creating, editing, printing
and saving documents. By using a word processor, it is possible to prepare reports,
announcements, journals, books, etc. Nowadays, Microsoft Word is the most popular word
processor for office applications. This product has so many features and we will discuss some
of the features in this experiment. We can learn more features by ourselves by using Help
Menu.
Typing Text:
When you start Word, a new, empty document file is automatically created, so you
face an empty page. You can start typing anything as you like. They will be seen on the
screen. Use the Enter key only at the end of Paragraphs! (Not at the end of each sentence or
line.)
Using the Menus:
On the top of the screen there is a bar that contains many drop-down menus (File,
Edit, View, etc). If you want to reach the menu bar with your keyboard, you can use the Alt
key. A lot of operations are offered in these menus, and you can select any of them to do the
corresponding operation, without having to write any commands. It is not possible to explore
all the menu items in one experiment; however you can learn them in time, easily, by yourself.
For this purpose, you may find the Help menu very helpful. Just use it. It is for you!
Department of CSE, PSNACET, Dindigul

COMPUTER PRACTICE LAB - I

File Menu: The items on this menu are related


with file operations. The default file type created
with Word is document type (*.doc). New
creates a new, empty document, Open opens a
document which was created and saved before,
Save saves the document to a disk (permanent
storage device), Save as is used to save another
(one more) copy of a file, with a different name,
Print is used to take a print-out of the document,
Close closes the currently open, active
document, Exit is used to quit from Word.

Edit Menu: Undo is used to cancel the last


action (operation) you have made, Repeat is
used to do a cancelled action once again,
Find is used to search for some word or
sentence in your document. Cut and Copy
should be used together with Paste. Cut ~
Paste combination is used to change the place
of a selected text by moving it into another
part of your document. Copy ~ Paste is used
to put an extra copy of a selected text into
another part of the document. Please refer to
Selecting Text part.

Using The Formatting Toolbar:

Changing Font Size & Font Type:


By default, the font size is usually 12. You can select any other value from the corresponding
combo box. Larger the value, larger the size of the font.
Ex:

This sentence is written with size 8.

This sentence is written with size 20.

By default, the font type is usually Times New Roman. You can select any other type.
Ex:
Department of CSE, PSNACET, Dindigul

COMPUTER PRACTICE LAB - I

This sentence is written using Times New Roman type.


This sentence is written using Courier New type.
This sentence is written using Arial type.

Bold, Italic and Underlined Texts:


You can find the buttons for these tree styles (B I U) on top of your screen. You can
use any combination of them to write Bold, Italic and Underlined texts.
Ex:

This is an italic sentence.


This is an underlined sentence.
This is underlined and bold.

This is a bold sentence.


This is both italic and underlined.
This is italic & underlined & bold.

Paragraph Alignment:
You can arrange the paragraphs as left aligned, right aligned, centered and justified
(i.e. aligned from both left and right margins) by clicking one of the corresponding buttons
shown above.
Ex:
The first paragraph in the Preliminary Explanations part is left aligned. The second
one is right aligned, and the third is centered. All the other paragraphs in the rest of the
lab sheet are justified.
Selecting Text:

With mouse
1. Move your mouse pointer to the beginning of the text you want to select
2. Click and hold the left mouse button
3. Move the mouse to the end of the text you want to select.
4. Release the mouse button.

With keyboard
1. Move the blinking cursor, by using the arrow keys, to the beginning of the text you
want to select
2. Press and hold the shift button
3. Move the cursor to the end of the text that you want to select
4. Release the shift button

When a text is selected, you see it highlighted. Now, you can do many operations on the
selected text. (ex: move (cut~paste), copy (copy~paste), underline, change size, type, color,
etc)
Copying or Moving a selected text:
To copy or move a text the first thing you have to do is to select it. Then click the
Copy or Cut item from the Edit menu depending on what you want to do. (Cut is used to
move). Move the cursor to the position that you want to insert the selected text. Click Paste in
the Edit menu.
Using Shortcuts and Access Keys:
Department of CSE, PSNACET, Dindigul

COMPUTER PRACTICE LAB - I

Many items in the menus have shortcuts that can be accessed by keyboard. Instead of
clicking these items with your mouse, sometimes you may prefer to use the shortcuts. For
example the shortcut for Save is Ctrl + S. Instead of clicking File and then Save, you can
hold down Ctrl key and press S. This will do the same thing.

Each menu item has one letter underlined. This is the access key of the item. If you get
bored of using mouse, just hold down the Alt key and press the corresponding letters to
travel in the menus.

Creating Scientific Notations:

Ex:

We can write scientific notations and mathematical formulas using MS-Word.


We can obtain the all scientific and mathematical symbols from Insert menu Symbol
We can also change the font effects from Format menu Font

(a+b)2 = a2 + b2+ 2 * a * b
sin2 + cos2 = 1
1.0E-6 or 1.0^-6 or 0.000001 sec.
2.34 * 10-5 + 5.67 * 10-9

Dividing a paragraph into columns:


Department of CSE, PSNACET, Dindigul

COMPUTER PRACTICE LAB - I

This paragraph is divided


into three (equal width)
columns. To divide a
paragraph into columns,
first select the entire
paragraph, then click
Columns item in the

Format menu, choose the


Number of columns
that you want to divide
the selected text into,
click the Line between
check box to put a tick
and make it checked if

you want to have a lines


between these columns. It
is also possible to have
columns with different
widths and arrange the
space
between
the
columns as we like

Constructing Tables
Table creation
Select from menu bar as Table Insert Table. And select no of rows and columns
required.

Split cells:
Select the cell to split, right click that cell and select the split cell option and give the
no of rows and/or columns.

Merge cells:
Select the number of rows or columns and right click it, select the merge cell option.

Insert Rows:
Place cursor in particular cell, Select from menu bar as
Table insert Rows Above/Rows Below.

Insert Columns:
Place cursor in particular cell, Select from menu bar as
Table insert Columns To The left / Columns to the right.

Department of CSE, PSNACET, Dindigul

COMPUTER PRACTICE LAB - I

EX. NO.: 1

CREATION OF AN ADVERTISEMENT IN MS-WORD

Aim
To create an advertisement using various drawing tools in MS-Word.
Procedure
1.
2.
3.
4.
5.
6.
7.
8.

Open a new document using File->New option and type text.


Place the different sized boxes in the document from the drawing toolbar.
Type the text in the boxes.
Fill the box with black color using Fill Color option from drawing toolbar.
Place the appropriate logo from the Insert-> Picture -> From File option.
Choose the appropriate WordArt gallery to place the text in boxes.
Choose the Bullets for the text from formatting toolbar.
Use all these options to create an advertisement as specified in exercise.

Sample Input and Output:

Result
Thus the advertisement is created in MS-Word using various drawing tools.

Department of CSE, PSNACET, Dindigul

COMPUTER PRACTICE LAB - I

EX. NO.: 2

MAIL MERGE USING MS-WORDS

Aim
To demonstrate the concept of mail merging in MS-Word.
Procedure
Creation of Mail Merge
1. Make the main document active, where we want to produce the letter.
2. Choose Mail Merge option from the Tools menu. Now the Mail Merge helper
dialog box appears.
3. In that box, click on the create button and choose the option Form Letters.
4. Click on the Form Letters because we are merging data source to document in
active window.
Creation of Data Source
5. Click on the Get data button and choose Create Data Source option.
6. Select the required fields for the data source ( Eg. Address fields) and then click ok
and then click OK and then save the data source with file name.
7. Now give data to that fields and Click OK, now your Data Source File is created.
8. The Mail Merge toolbar is automatically shown in your word document
Insertion of field names in the main document by using the mail merge toolbar
9. Place the cursor where we want to insert, and then click on the Insert Merge Field
button.
10. Choose First Field from the list box to tell Word to place the information from the
first row of the data source file in the form letter. The First merge Field is inserted
in the document.
11. Similarly we can insert other fields at the place we want.
12. If we want to merge data source in form letters then click on the Merge button on
Mail Merge helper dialog box. The resultant merged document will be displayed.

Sample Input and Output:


Department of CSE, PSNACET, Dindigul

COMPUTER PRACTICE LAB - I

Ordering Books
From
Mr. Ragul Singh,
IFCI Towers, Nehru Place,
New Delhi - 19
011-2556890
To
<Address Field>
Dear sir,
I shall be thankful to you send me the following books by RMS at an early
date. Also please give the nominal discounts as mentioned in your booklist.
Book Title
Mastering c++
The Java2
Windows
Programming
Programming
Visual c++

Author
No.of copies
K.R.Venugpopal
50
RajkumarBuyya
T.Ravishankar
Complete Refernce
30
Herbert Schildt

Price
Rs. 250

Charles Petzold

40

Rs. 300

David J.Kruglinski
George Sherherd
Scot Wingo

20

Rs. 400

Rs.350

We look forward to prompt delivery


Thanking you,
Yours Faithfully,
Ragul Singh
Ordering Books
From
Mr. Ragul Singh,
IFCI Towers, Nehru Place,
New Delhi - 19
011-2556890
To
`

SKS Solution Ltd Anil Kumar


SKS Education Solutions Limited
Pachai malai,
Dehradun

Dear sir,

Department of CSE, PSNACET, Dindigul

COMPUTER PRACTICE LAB - I

I shall be thankful to you send me the following books by RMS at an early


date. Also please give the nominal discounts as mentioned in your booklist.
Book Title
Mastering c++
The Java2
Windows
Programming
Programming
Visual c++

Author
No.of copies
K.R.Venugpopal
50
RajkumarBuyya
T.Ravishankar
Complete Refernce
30
Herbert Schildt

Price
Rs. 250

Charles Petzold

40

Rs. 300

David J.Kruglinski
George Sherherd
Scot Wingo

20

Rs. 400

Rs.350

We look forward to prompt delivery


Thanking you,
Yours Faithfully,
Ragul Singh
Ordering Books
From
Mr. Ragul Singh,
IFCI Towers, Nehru Place,
New Delhi - 19
011-2556890
To
BILLA GrawHill Co. DAVID Sons
BILLA GrawHill
SLP road
Periyar Salai
Salem
Dear sir,
I shall be thankful to you send me the following books by RMS at an early
date. Also please give the nominal discounts as mentioned in your booklist.
Book Title
Mastering c++
The Java2
Windows
Programming
Programming
Visual c++

Author
No.of copies
K.R.Venugpopal
50
RajkumarBuyya
T.Ravishankar
Complete Refernce
30
Herbert Schildt

Price
Rs. 250

Charles Petzold

Rs. 300

40

Rs.350

David J.Kruglinski

Department of CSE, PSNACET, Dindigul

COMPUTER PRACTICE LAB - I

George Sherherd
Scot Wingo

20

Rs. 400

We look forward to prompt delivery


Thanking you,
Yours Faithfully,
Ragul Singh
Result
Thus the concept of Mail Merging is illustrated.

Department of CSE, PSNACET, Dindigul

10

CONSTRUCTING FLOW CHART IN MS-WORD


Flowchart:
A flowchart is a schematic representation of an algorithm or a process, or the stepby-step solution of a problem, using suitably annotated geometric figures connected
by flow lines for the purpose of designing or documenting a process or program.
Symbols:
A typical flowchart may have the following kinds of symbols:
Start and end symbols, ovals or rounded rectangles, usually containing the word
"Start" or "End", or another phrase signaling the start or end of a process, such as
"submit enquiry" or "receive product".
Arrows, showing what's called "flow of control" in computer science. An arrow
coming from one symbol and ending at another symbol represents that control
passes to the symbol the arrow points to.
Processing steps, represented as rectangles.
Input/output, represented as a parallelogram.
Conditional (or decision), represented as a diamond. These typically contain a
Yes/No question or True/False test. This symbol is unique in that it has two arrows
coming out of it, usually from the bottom point and right point, one corresponding
to Yes or True, and one corresponding to No or False. The arrows should always
be labeled. More than two arrows can be used, but this is normally a clear
indicator that a complex decision is being taken, in which case it may need to be
broken-down further, or replaced with the "pre-defined process" symbol.
A number of other symbols that have less universal currency, such as:
o A Document represented as a rectangle with a wavy base;
o A Manual input represented by parallelogram, with the top irregularly
sloping up from left to right. An example would be to signify data-entry
from a form;
o A Manual operation represented by a trapezoid with the longest parallel
side at the top, to represent an operation or adjustment to process that can
only be made manually.
o A Data File represented by a cylinder
Flowcharts may contain other symbols, such as connectors, usually represented as
circles, to represent converging paths in the flow chart. Circles will have more than one
arrow coming into them but only one going out. Some flow charts may just have an arrow
point to another arrow instead. These are useful to represent an iterative process (what in
Computer Science is called a loop). A loop may, for example, consist of a connector
where control first enters, processing steps, a conditional with one arrow exiting the loop,
and one going back to the connector. Off-page connectors are often used to signify a
connection to a (part of another) process held on another sheet or screen. It is important to
remember to keep these connections logical in order. All processes should flow from top
to bottom and left to right.

EX. NO. :3

DRAWING FLOW CHART USING MS-WORD

Aim:
To draw a flow chart to find factorial of a number using MS-Word.
Algorithm:
1. Read a number to find the factorial of it
2. Assign value 1 to variable M, F
3. Multiply the vlaues of varible, F with variable, M
4. Check whether value of variable, M is equal to value of variable, N
4.a. Display the Factorial of the given number, N
4.b. Otherwise, increment the value of the varible, M by 1
Sample Output:

Result:
Thus, the flow chart to compute Factorial of a given number was constructed
successfully.

INTRODUCTION TO MICROSOFT EXCEL


Objectives:
Learning the basic features and facilities of spreadsheets and experiencing on Excel.

Preliminary Explanations:
In the following experiment you will learn about Excel, a very popular
spreadsheet. This is also application software. Spread sheets can be used for evaluating
results of surveys and elections, preparing statistical summaries, taking financial
decisions, making accounting calculations, etc
When you start Excel, we will find a worksheet (tables) in which you can write
text, numbers or formulas. Texts can be used to create titles or labels, numbers are the
data that we obtain from somewhere, and formulas are used to do some operations or
calculations on these numbers.
Tables are formed of columns and rows. Each box in a table (the intersection of a
row and a column) is called a cell. Columns are named as A, B, C, D, etc, and rows are
named as 1, 2, 3, 4, etc Cells are named as A1, A2,, B1, B2,,, Z1, Z2,
depending on the location they are found.
Ranges:
In an Excel Worksheet there are 16384 rows and 256 columns. Range is a group
(rectangular block) of cells. A column or a row, for example, is a range, part of a column
or a row is also a range. Ranges are represented with two cells: The first and the last.
Ex:
A1:A5 is a range of 5 cells in the A column. More strictly, A1, A2, A3, A4, A5
B2:E4 is a range of 12 cells. The cells are B2, B3, B4, C2, C3, C4, D2, D3, D4, E2,
E3, E4.
Formulas:
In Excel, you can write formulas to do some calculations on cells or ranges of
cells. For example, you can add the values in F1 and F2, and write the result into F3, by
writing =F1+F2 into F3.
Functions:
In these formulas you can also use some functions like SUM(), AVERAGE(),
SIN(), etc. For example, instead of =F1+F2, you may use = SUM(F1:F2). Of course for
adding only two numbers it may not be a very bright idea to use the function SUM(), but
if we have many numbers to add, it will certainly be very useful.
If we want to see the complete list of these functions, just click the Function item in the
Insert menu.

Writing Formulas:
To write a formula into a cell, you should first put an equal sign (=) and then write
the corresponding formula.
Ex: Write 1, 2, 3, 4, 5 into A1, A2, A3, A4 and A5 respectively. Then write
=SUM(A1:A5) into the cell A6.
Do you see the result 15 in A6? Now change the number in any of the cells in range
A1:A5 and see that the value of A6 is automatically recalculated.
Copying a formula to other cells:
Suppose you want to add the numbers in B1:B5, also. Instead of writing
=SUM(B1:B5) into B6, you can just copy A6 to B6. You know that the formula in A6 was
=SUM(A1:A5) but it will be automatically turned to =SUM(B1:B5) during the copy
operation.
Constant Addressing vs Relative Addressing:
As you see in the section above, when you copy some formula to another cell, the
range in it automatically changes. This is because there is relative addressing. To prevent
this, you can use the $ sign in front of the cell addresses. Suppose that you write
=SUM($A$1:$A$5) in A6. When you copy it to B6, the formula will remain exactly the
same, and you will see 15 in both A6 and B6.
Using the Help Menu:
Sometimes, you may forget how to do something, or you may want to learn
something new which would be very useful for what you are intending to do. In these
cases, you can just refer to the Help menu. Try it! It is like a teacher who is always ready
to answer your questions and solve your problems.
Sorting a column:
You can sort some rows (or some range of cells) in the table, by any column, in
ascending or descending order. To do this, just select a range of cells, click the Sort item
in the Data menu, and select the columns by which you want to do the sort. It is so
simple!
Inserting Charts into your worksheet:
Charts (graphs) are visual representations of numbers. Instead of seeing many
numbers all together, we usually prefer to see a chart that represents everything visually.
Whenever there is an election, for example, all the TV channels show the results by using
some kind of graphs. It is more easily understandable to human beings. To insert a chart,
just select the corresponding columns (or ranges), and click Chart item in the Insert
menu. Then select the chart type that you want to use and click Next two times. Now
enter the Chart title, and select a data label style, if you want, and click Next again. Be
sure that As object in: Sheet 1 is selected and click Finish.
Now the chart is inserted into your worksheet. Change the values in some of the
cells of the range that was used to prepare the chart. Realize that the chart is
automatically updated to reflect these changes.

Experimental Work:
1. Prepare the following table: (Course should be in A1!)
Course
Credit
Grade Worth Credit X
Worth
CMPE101
4A
4
PHYS101
4B
3
ELT101
3 B2.7
MATH151
4 B+
3.3
MATH163
3 A3.7
Total Credit X
Worth:
Total Credit:
Average (GPA):
2.
3.
4.
5.
6.
7.
8.

Write =B2*D2 in E2. Now, you should see 16 in E2.


Copy E2 to E3, E4, E5 and E6. You should see 12, 8.1, 13.2, 11.1 respectively.
Write =SUM(E2:E6) in G8. Now you should see 60.4 in G8.
Write =SUM(B2:B6) in G9. You should see 18 in G9.
Write =G8/G9 in G10. You should see 3.355556.
Decrease the number of digits after the decimal point to two. i.e obtain 3.36.
Change C3 to A and D3 to 4. Realize that E3 changed automatically to 16, G8 to 64.4,
G10 to 3.58
9. Sort the table in descending order by the Worth column. To do this, you should
select the whole (!!!) table, click the Sort item in the Data menu.
10. Insert a Pie chart into your worksheet to show the effect of each course on your GPA.
To do this you should select A2:A6 and E2:E6 and then insert the chart. The chart will
show what is the percentage effect of each course grade on your GPA. The effect
depends on both the credit of the course and your grade. The chart should look like
this:

Effect of courses on my GPA


ELT101
%13

CMPE101
%25

MATH151
%20
MATH163
%17

EX. NO. :4

CMPE101
PHYS101
MATH163

PHYS101
%25

MATH151
ELT101

SPREAD SHEET CREATION IN MS-EXCEL

Aim:

To create a spread sheet to analyze the marks of the students of a class and
also to create appropriate charts

Algorithm
Step 1:
Step 2:
Step 3:
Step 4:

Enter the Student Name, Marks in three subjects.


Place the cursor in E2, type = SUM (B2...D2).
Place the cursor in F2, type = AVERAGE (B2.D3).
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",
CLASS"))))
Step 6: Copy the formulas to the remaining students
Step 7: Finally, the worksheets is shown as follows:

"THIRD

Step 8: To create a chart for the student marks


Step 9: Click on the Chart Wizard on the Formatting Toolbar.
Step10: It shows the Chart Wizard- step 1 of 4 chart type dialog box, choose
The Chart type and click on next
Step11: It shows the Chart Wizard-Step 2 of 4-Chart Source Data dialog box
Choose the chart source and click on Next
Step 12: It shows the Chart Wizard-Step 3 of 4-Chart Options dialog box,
Choose the chart Title, X-axis and Y-axis labels and click on Next
Step 13: It shows the Chart Wizard-Step 3 of 4-Chart Location dialog box,
Choose the chart Location and click on Next
Step 14: Then Click on Finish.
Step 15: Now the chart is created.
Result
Thus, the Spread sheet to analyze the marks of the students of a class and also
appropriate charts are created.
POWERPOINT

`
PowerPoint is a presentation tool helps you create eye catching and effective
presentation in manner of minutes. A presentation comprises of individual slides arranged
in a sequential manner. Normally, each slide would cover a brief topic.
GETTING STARTED

Open PowerPoint and you will be prompted by a dialog box with four choices.
Each of these options are explained on this page. If Powerpoint is already open or this
box does not appear, select File\New menu bar
AUTOCONTENT WIZARD

The Auto content wizard provides templates and ideas for a variety of presentation
types. Page through the wizard by clicking the Next button on the bottom of each page
after making necessary choices
DESIGN TEMPLATE

PowerPoint provides many templates with different backgrounds and text


formatting to begin your presentation. Preview each design by highlighting the template
name on the list. Press OK after you have chosen the design.
BLANK PRESENTATION

Select Blank Presentation to build the presentation from scratch with no preset
graphics
VIEWS

PowerPoint gives you four screen layouts for constructing your presentation in
addition to the slideshow. You can select the page view by clicking the buttons just
above formatting toolbar and the bottom of the page
NORMAL VIEW

This screen is split into three sections showing the presentation outline on the left,
the slide in the main window, and notes at the bottom.
SLIDEVIEW

The slide view displays each slide on the screen and is helpful for adding images,
Formatting text and adding background styles.
OUTLINEVIEW

The presentation outline is displayed on the majority of the screen with small
windows for the slide and notes. This view is recommended for editing text.

EX. NO. :5

POWER POINT PRESENTATION

Aim
To create the presentation for the department using Powerpoint using animation,
design templates and Effective presentation
Algorithm
Step 1: Open a Blank Presentation
Step 2: Choose WordArt option from the picture in insert menu or click on WordArt
button from the drawing tool bar.
Step 3: From the WordArt gallery choose the appropriate style then click OK.
Edit WordArt Text dialog box appears, type your text here, then click OK.
Step 4: Choose Clipart option from the picture in Insert Menu selection or click
on Clipart button from the Drawing Tool Bar
Step 5: Insert clipart dialog box appears, from there choose required clipart then
ok. Follow the above steps to complete below slides

PSNA COLLEGE OF
ENGINEERING AND
TECHNOLGY

Result
Thus, the presentation for the department using power point using animation,
design templates and Effective presentation is created
EX. NO. :6 COMPUTATION OF AGE IN TERMS OF YEARS,
MONTHS AND DAYS
Aim
To write a C program to find the age in terms of years, months and days.
Algorithm
Step 1: Read the date of birth through bd,bm,by.
Step 2: Read the current date through cd, cm,cy.
Step 3: btotal <-(bd+(bm*30)+(by*366)).
Step 4: ctotal <-(cd+(cm*30)+(cy*366)).
Step 5: total <- ctotal- btotal.
Step 6: days<- total % 30.
Step 7: months<- total / 30.
Step 8: years<- months % 12.

START
Step 9: Print total, years, months, days.
Flowchart
READ bd, bm, by

cd,cm,cy
Compute:
btotal <-(bd+(bm*30)+(by*366))
ctotal <-(cd+(cm*30)+(cy*366))
total <- ctotal- btotal
Compute:
Years<-total/365;
Months<-(total%365)/30;
Days<-(total%365) %30;

Display years,
months, days,
total

STOP

Program
#include<stdio.h>
#include<conio.h>
void main()
{
int bd,bm,by,cd,cm,cy;
int btotal,ctotal,total,days,month,months,years;
clrscr();
printf("enter your date of birth in the order of date,month and years\n");
scanf("%d%d%d",&bd,&bm,&by);
printf("enter current date in the order of date,month and year\n");
scanf("%d%d%d",&cd,&cm,&cy);
btotal=(bd+(bm*30)+(by*365));
ctotal=(cd+(cm*30)+(cy*365));
total=(ctotal-btotal);
printf("total days are: %d \n",total);
years=total/365;
months=(total%365)/30;
days=(total%365)%30;
printf("\n%d your age in \n %d years \n %d months \n %d days
\n",total,years,months,days);
getch();
}
Sample Input and Output:
Enter your date of birth in order of date, month and years
01 01 1983
Enter current date in order of date, month and years
11 08 2009
Total days are: 9710
Your age is
26 years
7 months
10 days

Result:
Thus the C program to find the age in terms of years, months and day was written
and executed successfully.
DECISION MAKING
C program is a set of statements which are normally executed sequentially in the
order in which they appear. In some situations ,change the order of execution of
statements based on certain conditions This involves a kind of decision making to
see whether a particular condition has occurred or not and then direct the computer to
execute statements.
C language possesses such decision making capabilities and supports the
following statements known as control or decision making statements.
1. if statement
2. switch statement
3. conditional operator statement
4. goto statement
if Statement:
The, if statement is a powerful decision making statement and is used to control
the flow of execution of statements. It allows the computer to evaluate the expression first
and then depending on whether the value of the expression is true or false. The, if
statement may be implemented in different forms depending on the complexity of
conditions to be tested.
1. Simple if statement
2. if.else statement
3. Nested ifelse statement
4. else if ladder
Simple if statement:
General form:
if (test expression)
{
statement-block)
}
statement-x;
The ifElse statement:
The if..else statement is an extension of the simple if statement.
General form:
if(test expression)

{
True-block statements(s)
}
else
{
False-block statements(s)
}
statement-x
Nesting of if else statements
When a series of decisions are involved, more than one ifelse statement is
nested.
General Form:
if (test condition 1)
{
if (test condition 2)
{
statement -1;
}
else
{
statement -2;
}
}
else
{
statement-3;
}
statement x;
The else if ladder:
A multipath decision is a chain of ifs in which the statement associated with each
else is an if.
General form:
If(condition 1)
Statement-1;
Else if (condition 2)
Statement-2;
Else if (condition 3)
Statement-3;
Else if (condition n)
Statement-n;
else
default statement;
statement-x;

SWITCH STATEMENT:
The C Language has a built-in multiway decision statement known as a switch.
The switch statement tests the value of a given variable (or expression) against a list of
case values and when a match is found, a block of statements associated with that case is
executed.
General form
Switch(expression)
{
case value-1:
block-1
break;
case value-2:
block-2
break;
..
..
default:
default-block
break;
}
statement-x;

CONDITIONAL OPERATOR STATEMENT:


The C language has an unusual operator, useful for making two-way decisions.
This operator is a combination of ? and : and takes three operands.
General form:
Conditional expression ? expression 1 : expression 2
The conditional expression is evaluated first. If the result is nonzero, expression1
is evaluated and is returned as the value of the conditional expression. Otherwise
expression 2 is evaluated and its value is returned..
GOTO STATEMENT:
C supports the goto statement to branch unconditionally from one point to another in
the program. The goto requires a label in order to identify the place where the branch is
to be made.
General form:
Forward jump:
goto label;
-------------label;
statement;
Backward jump:

Label:
Statement;
--------goto label;
LOOPING STATEMENT
Most real programs contain some construct that loops within the program,
performing repetitive actions on a stream of data or a region of memory. There are several
ways to loop in C. The three common methods of looping are,
While loop
Do/while loop
For loop
while Loop:
The while loop continues to loop until, the conditional expression becomes false.
The condition is tested upon entering the loop. In a While Loop, the expression is
evaluated when the program enters the top of the loop. If the expression is true, the
statements within the loop are executed. When the bottom of the code block is reached,
program flow is directed back to the top of the loop and the conditional is re-evaluated.
As long as the conditional is evaluated as true, the process repeats. IF the conditional is
evaluated as false, then the code block is skipped. The syntax for the while loop is shown
below,
while (expression)
{
...block of statements to execute...
}
The flowchart for a While Loop is shown below.

do / while Loop:
The Do/While loop is very similar to the while loop. The major difference is that
the expression or conditional is tested at the bottom of the loop. This means that the body

of the loop is executed at least one time regardless of the results of the conditional. If the
result of the conditional is true, then the loop body is repeated. This process is repeated
until the conditional is evaluated as false. The flow chart and the syntax for the Do/while
loop is given below,
do
{
Perform the statements located between the braces
} while (this conditional expression is true);

for loop:
The For Loop is traditionally used to perform a task or repetitive event for a
known number of iterations or in other words, it is used to implement count-controlled
loops. For loop is made up of an initial condition, a conditional expression, a modifier,
and the body or the code block.

When for loop is encountered, the initial condition is executed.


The conditional expression is then evaluated as either true or false.
If the conditional is determined to be true, then the body of the loop is
executed.
Upon reaching the bottom of the loop, the modifier is executed.
Program control is then returned to the conditional.
The conditional expression is re-evaluated, and if true, the body of the loop is
executed again.
Each time the bottom of the code block is reached, the modifier is executed.
The loop continues to be executed until the conditional is evaluated as no
longer true.
The flowchart for a For Loop is shown below. The basic shape of the
flowchart resembles that of a While Loop.

The difference or characteristic that determines that it is a For Loop is that the
initial condition, conditional, and modifier all refer to the same variable. The
syntax for the FOR loop is given below along with the flow chart,

for ( variable initialized ; conditional expression ; <increment / decrement>)


{
Perform these statements while the conditional expression is true
}

EX. NO. : 7

THE SIMPLE MENU DRIVEN CALCULATOR USING


SWITCH STATEMENT

Aim
To write a simple menu driven calculator program using switch statement.
Algorithm
Step 1: Display the menu
Step 2: Read the two variables a & b
Step 3: Enter the option code
Step 4: Evaluate option code with case constants
Step 4.1: case=1
c=a+b
print c
goto step 6
Step 4.2: case=2
c=a-b

print c
goto step 6
Step 4.3: case=3
c=a*b
print c
goto step 6
Step 4.4: case=4
c=a/b
print c
goto step 6
Step 4.5: case=5
Exit
Step 5: Entered case option is invalid code then print Invalid operation Code

Flowchart

Start

Q
Display the Menu

Read choice

No

If n<=4
& n>0

A
Yes

Read a,b
No
Swit
ch

n
Yes
Yes
Case
1
No

c=a+b

Print c
Yes
Case
2

No

c=a-b

Print c
C

Yes

c=a*b

Case
3
No

Print c
Yes

c=a/b

Case
4
No

Print c
Yes

Case
5

A
No

Yes

while
(ch<=5)

No

Print invalid
operation

Stop

Program
#include <stdio.h>
#include <conio.h>
void main()
{
int a,b,c,ch;
clrscr();
do
{
printf("****MENU****\n");
printf("1.Addition\n");
printf("2.Subtraction\n");
printf("3.Multiplication\n");
printf("4.Division\n");
printf("5.exit\n");
printf("enter your choice\n");
scanf("%d",&ch);
if(ch<=4&&ch>0)
{
printf("enter two numbers\n");
scanf("%d%d",&a,&b);
}
switch(ch)
{
case 1:
c=a+b;
printf("Addition:%d\n",c);
break;
case 2:
c=a-b;
printf("Subtraction:%d\n",c);
break;
case 3:
c=a*b;
printf("Multiplication:%d\n",c);
break;
case 4:
c=a/b;
printf("Divition:%d\n",c);
break;
case 5:
exit(0);
break;
default:
printf("invalid operation code");
}
}while(ch<=5);
getch();
}

Sample input and output


****MENU****
1.Addition
2.Subtraction
3.Multiplication
4.Division
5.exit
enter your choice
1
enter two numbers
10
20
Addition:30
****MENU****
1.Addition
2.Subtraction
3.Multiplication
4.Division
5.exit
enter your choice
2
enter two numbers
30
20
Subtraction:10
****MENU****
1.Addition
2.Subtraction
3.Multiplication
4.Division
5.exit
enter your choice
3
enter two numbers
45
2
Multiplication:90
****MENU****
1.Addition
2.Subtraction
3.Multiplication
4.Division
5.exit
enter your choice
5
Result
Thus the simple menu driven calculator program was written and executed
successfully.

EX.NO.:8

PROGRAM TO PRINT MULTIPLICATION TABLE FOR THE


GIVEN NUMBER

Aim
To write a C program to print multiplication table for the given number.
Algorithm
Step 1: Read which multiplication table you want m
Step 2: Read the upper limit n.
Step 3: Assign 1 to a.
Step 4: Assign m to total.
Step 5: for i=1 to n
Step 5.1:Print a,m,total
Step 5.2: a <- a+1.
Step 5.3: total <- total+m
Flowchart:

Program
#include<stdio.h>
#include<conio.h>
void main()
{
int n,m,i,total,a=1;
clrscr();
printf("enter which multiplication table you want?\n");
scanf("%d",&m);
printf("enter limit of the multiplication table\n");
scanf("%d",&n);
total=m;
for(i=1;i<=n;i++)
{
printf("%d x %d = %d\n", a,m,total);
a=a+1;
total=total+m;
}
getch();
}

Sample Input and Output:


Enter which multiplication table you want?
7
Enter limit of the multiplication table
5
7 x 1=7
7 x 2=14
7 x 3=21
7 x 4=28
7 x 5=35

Result
Thus the C program to print multiplication table for the given number was written
and executed successfully.

EX.NO.:9

PROGRAM TO CHECK PALINDROME NUMBER

Aim
To check the given number is Palindrome or not.
Algorithm
Step 1: Enter the number
Step 2: Set a loop upto the number is not equal to zero.
Step 3: remnum%10
Step 4: sumsum+rem
Step 5: rnumrnum*10+rem
Step 6: numnum/10
Step 7: After the end of the loop print the sum and reverse number of the digit.
Step 8: Find whether the reverse number is equal to the given number or not.
If equal the number is palindrome.
Step 9: If not equal the given number is not palindrome.
Flowchart
Start
Read
num
a = num
sum =0
rnum = 0

No

If (num!
=0)

Yes
Rem =num % 10
Sum =sum+rem
Rnum = rnum*10 + rem
num = num /10

If
(a==rnu
m)

Print
sum,re
m

No

Yes
Print
Number is
palindrome

Start

Print Number
is not a
palindrome

Program
#include <stdio.h>
#include <conio.h>
void main()
{
int a,num,sum=0,rnum=0,rem;
clrscr();
printf("Enter the number\n");
scanf("%d",&num);
a=num;
while(num!=0)
{
rem=num%10;
sum=sum+rem;
rnum=rnum*10+rem;
num=num/10;
}
printf("The reverse number of the %d is %d\n",a,rnum);
if(a==rnum)
printf("%d is palindrome\n",a);
else
printf("%d is not a palindrome\n",a);
getch();
}

Sample Input and Output:


Enter the number
232
The reverse number of the 232 is 232
232 is palindrome
Enter the number
123
The reverse number of the 123 is 321
123 is not a palindrome

Result
Thus the palindrome program was written and executed successfully.

EX.NO.:10

PROGRAM TO CHECK PRIME NUMBER

Aim
To find whether the given number is palindrome or not.
Algorithm
Step 1: Read the number
Step 2: i2
Step 3: Is i<=num-1 else goto end
Step 4: Is num%i=0
Step 4.1: print not prime.
Step 4.2: goto end
Step 5: i i+1
Step 6: goto Step 4
Step 7: Is i=num print prime.
Flowchart
Start
Sta
Enter the number

No

While(i
<=num
-1)
i++

Print Prime
Yes

No

If(n%i
= = 0)

Yes
Print not prime

Stop

Program

#include <stdio.h>
#include <conio.h>
void main()
{
int num,i=2;
clrscr();
printf("Enter the number\n");
scanf("%d",&num);
while(i<=num-1)
{
if(num%i==0)
{
printf("%d is not a prime number\n",num);
break;
}
i++;
}
if(i==num)
printf("%d is prime number\n",num);
getch();
}
Sample Input and Output:
Enter the number
7
7 is prime number
Enter the number
9
9 is not a prime number

Result
Thus, the prime number program was written and executed successfully.

EX.NO.:11

GENERATION OF FIBONACCI SERIES

Aim
To write a program to print the Fibonacci series.
Algorithm
1. Read the value r.
2. Assign a=0, b=1 and c=0.
3. Print the value of a and b.
4. Compute c= a + b.
5. Check the condition (c<=r), go to step 6. Otherwise step 7.
6. Print the value of c.
7. Assign a=b and b=c.
8. Repeat the steps 4 to 7 until (c<=r)
Flowchart

Program
#include<stdio.h>
void main( )
{
int i,a,b,c,r;
clrscr( );
printf(Enter the range:);
scanf(%d,&r);
a=0;b=1;
printf(%d,a);
printf(\n%d,b);
printf(\n);
c=0;
do
{
c=a+b;
if(c<=r)
printf(%d\n,c);
a=b;
b=c;
}
while(c<=r);
getch( );
}
Sample Input and Output:
INPUT:
Enter the range : 10
OUTPUT:
0
1
1
2
3
5
8

Result
Thus, the program for Fibonacci series is implemented.

EX.NO.:12

EVALUATION OF SINE SERIES

Aim
To write a program to evaluate sine series sin(x) = x x3/3! +x5/5!+.+xn/n!
Algorithm
1. Read the values of n and angle
2. Compute x = angle (angle*3.141592/180)
3. Assign term=x, sum=x and i=1
4. Repeat the steps 5 to 7 until i<n.
5. Compute term =-(term*x*x) / (2*i)*(2*i+1)
6. Compute the sum =sum +term
7. Compute i=i+1
8. Display the values of angle, x and sum.
Flowchart

Program
#include<stdio.h>
#include<conio.h>
void main( )
{
int i ,n ;
float x,angle,term,sum;
clrscr( );
printf(\n Enter number of terms and angle:);
scanf(%d%f,&n,&angle);
x=angle*3.141592/180;
term =x;
sum=x;
for(i=1;i<n;i++)
{
term=((-term*x*x)/((2*i)*(2*i+1)));
sum=sum+term;
}
printf(\n Entered angle =%f,angle);
printf(\n Its radian value =%f,x);
printf(\n Value of sin(x) =%f,sum);
getch( );
}
Sample Input and Output:
INPUT:
Enter number of terms and angle:3

90

OUTPUT:
Entered angle =90.000000
Its radian value =1.570796
Value of sin(x) =1.004525

Result
Thus the program for the sine series is generated and implemented.

EX.NO.:13
Aim

EVALAUTION OF COSINE SERIES

To write a program to evaluate cosine series sin(x) =x x2/2! +x4/4!+.+xn/n!


Algorithm
1. Read the values of number of terms (n) and angle.
2. Compute the radian value using the angle.
3. Initialize the value of term and sum as 1.
4. Repeat the steps 5 to 7 until the number of terms (n).
5. Compute the term value for each iteration.
6. Compute the sum for the cosine series.
7. Increment the iterative value.
8. Display the values of angle, radian value and sum of the cosine series.
Flowchart

Program
#include<stdio.h>
#include<conio.h>
void main( )
{
int i ,n ;
float x,angle,term,sum;
clrscr( );
printf(\n Enter number of terms and angle:);
scanf(%d%f,&n,&angle);
x=angle*3.141592/180;
term =1;
sum=1;
for(i=1;i<n;i++)
{
term=((-term*x*x)/((2*i)*(2*i-1)));
sum=sum+term;
}
printf(\n Entered angle =%f,angle);
printf(\n Its radian value =%f,x);
printf(\n value of cos(x) =%f,sum);
getch( );
}
Sample Input and Output:
INPUT:
Enter number of terms and angle:3 90
OUTPUT:
Entered angle =90.000000
Its radian value =1.570796
value of cos(x) =0.019969

Result
Thus the program for the cosine series is generated and implemented.

EX.NO.:14

FINDING THE LARGEST AND SMALLEST NUMBER


USING ARRAYS

Aim
To write a program to find the largest and smallest number using Array.
Algorithm
1. Read the number of values (n).
2. Initialize the iterative variable i=0.
3. Repeat the steps 4 & 5 until no. of values minus 1(n-1).
4. Read the elements in an array.
5. Increment the iterative variable.
6. Assign the first element of an array to the small and big variables.
7. Repeat the steps 8 to 10, until no. of values minus 1 (n-1).
8. If the array element is greater than big element,
Assign the element to the big variable.
Otherwise
goto step 10.
9. If the array element is smaller than small element,
Assign the element to the small variable.
Otherwise
goto step 10.
10. Increment the iterative variable.
11. Display the biggest element in the list.
12. Display the smallest element in the list.

Flowchart

start

Read number of elements (n)

Repeat process until n-1

Read the elements in an


array a[i]

Next i

Assign the first element to the small


and big variables

Repeat process until n-1

Check the
Array
element>bi
g
Y
Assign the element to the big
variable

Next i

Display the values of big,small variables

Stop

Check the
Array
element<sm
al
Y
Assign the element to the
small variable

Program
#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,a[10],big,small;
clrscr();
printf(Enter the size of the list \n);
scanf(%d,&n);
printf(Enter the elements\n);
for(i=0;i<n;i++)
scanf(%d,&a[i]);
small=a[1];
big=a[1];
for(i=1;i<n;i++)
{
if(a[i] >big)
big =a[i];
else if (a[i] <small)
small =a[i];
}
printf(\n Biggest element in the list:%d\n,big);
printf(\n smallest element in the list:%d \n,small);
getch( );
}
Sample Input and Output:
INPUT:
ENTER THE SIZE OF THE LIST
5
Enter the elements
65
45
12
85
68
OUTPUT:
Biggest element in the list : 85
Smallest element in the list : 12

RESULT:
Thus the program for finding largest and smallest number using array is
implemented.
.

EX.NO.: 15

SORTING THE NUMBERS IN AN ARRAY

Aim
To write a C program to sort the numbers in an array in Ascending and
Descending order.
Algorithm
1. Read the number of values (n).
2. Initialize the iterative value (i) to 0.
3. Repeat the steps 4 to 5 until the number of values minus 1 (n-1).
4. Read the elements in an array a[i].
5. Increment the iterative value.
6. Initialize the iterative value (i) to 0.
7. Repeat the steps 8 to 12 until the number of values minus 1 (n-1).
8. Assign the iterative value j as i+1.
9. Repeat the steps 10 - 11 until iterative value (j) less than no. of values (n).
10. If a[i]>a[j] then
Swap the values using temporary variable.
11. Increment the iterative value (j)
12. Increment the iterative value (i)
13. Display the array elements in the ascending and descending order.

Flow chart
Start
Sta
Read the number of values

Repeat the process until


n-1
Read the elements in an array a[i]

Next i

Repeat the loop i from 0 to n1


Repeat the loop j from i+1
to n

a[i]>a[
j]

Swap the elements

Next j

Next i

Repeat loop i from 0 to


n
Print the sorted array
elements in ascending
order
Next
i

Repeat loop i from n-1 to


0
Print the sorted array
elements in descending
order
Next
i

Stop
Program
#include<stdio.h>
#include<conio.h>
void main( )
{
int i,j,n,a[20],temp;
clrscr( );
printf(Enter the size of the array \n);
scanf(%d,&n);
printf(Enter the elements of the array:\n);
for(i=0;i<n;i++)
{
scanf(%d,&a[i]);
}
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{

if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
printf(The elements sorted in the Ascending order:\n);
for(i=0;i<n;i++)
{
printf(%d\t,a[i]);
}
printf(The elements sorted in the Descending order:\n);
for(i=n-1;i>=0;i--)
{
printf(%d\t,a[i]);
}
getch( );
}
Sample Input and Output:
INPUT:
Enter the size of the array
5
Enter the elements of the array:
20
44
3
56
12
OUTPUT:
The elements sorted in the Ascending oder
3
12
20
44
56
The elements sorted in the Descending oder
56
44
20
12
3
Result
Thus the C program to sort the numbers in an array in Ascending and descending order
has been done and the output is verified.

EX.NO.:16

IMPLEMENTATION OF BUBBLE SORTING

Aim
To write a C program to sort the numbers using bubble sorting method.
Algorithm
1. Read the number of values (n).
2. Initialize the iterative value (i) to 0.
3. Repeat the steps 4 to 5 until the number of values minus 1 (n-1).
4. Read the elements in an array a[i].
5. Increment the iterative value.
6. Initialize the iterative value (i) to 0.
7. Repeat the steps 8 to 12 until the number of values minus 2 (n-2).
8. Assign the iterative value j as 0.
9. Repeat the steps 10 - 11 until iterative value (j) less than (n-2)-i.
10. If a[j]>a[j+1] then
Swap the values using temporary variable.
11. Increment the iterative value (j)
12. Increment the iterative value (i)
13. Display the array elements in the sorted order.

Flow chart
Start
Sta
Read the number of values

Repeat the process until


n-1
Read the elements in an array a[i]

Next i

Repeat the loop i from 0 to n2


Repeat the loop j from 0 to (n2)-i

a[j]>a[j+
1]

Swap the elements

Next j

Next i

Repeat loop i from 0 to


n-1
Print the sorted array
elements

Next
i

Stop
Program
#include<stdio.h>
#include<conio.h>
void main( )
{
int i,j,n,a[20],temp;
clrscr( );
printf(Sorting the elements using bubble sort\n);
printf(Enter the size of the array \n);
scanf(%d,&n);
printf(Enter the elements of the array:\n);
for(i=0;i<=n-1;i++)
{
scanf(%d,&a[i]);
}
for(i=0;i<=n-2;i++)
{
for(j=0;j<=n-2-i;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
printf(The elements sorted using bubble sort are:\n);
for(i=0;i<n-1;i++)
{
printf(%d\t,a[i]);
}
getch( );
}

Sample Input and Output:


INPUT:
Sorting the elements using bubble sort
Enter the size of the array
5
Enter the elements of the array:
30
24
13
6
52
OUTPUT:
The elements sorted using bubble sort are
6
13
24
30
52

Result
Thus the C program to sort the numbers in an array using bubble sort has been
done and the output is verified.

EX.NO.:17

REVERSING THE ELEMENTS IN AN ARRAY

Aim
To Display all the elements of an array in reverse order using functions
Description
Array

The elements are stored in a memory locations in sequential order is called Arrays.

It is a linear list which can be accessed by indexes.

It is a finite set of homogeneous elements where finite specifies there must be a


specific number of elements in the array & homogeneous specifies all the
elements in the array must be of same type

For Ex: It is possible to declare an array for the set of salaries of group of employees.
i.e.,

int salary[10];
where,

10 ----- referred as index or subscript.

Similarly, an array of 10 integers can be specified by


int a[10];
Operations: There are 2 operations that can be performed that access an array
1. Extraction
It is the function that tells retrieving a data element from an array. This
Function accepts 3 information
An array
An index
The element that is returned from that array Ex: printf(a[i]);
2. Storing
It is function that tells to store the data to an array.. This function requires
3 information
An array
An index
An element which is assigned to an array Ex: a[i]=data;

Lower Bound: The smallest element of an array index is referred as lower bound,
which is fixed at 0 the location of an array.

Upper Bound: The highest element of an array index is referred as upper bound,
which is depends on the program execution.

Range: It specifies the no. of elements in an array. It can be specified by the


following mentioned formulae,

Range=Upperbound-lowerbound+1

During the execution of the program these bounds may change.

It is the useful technique to declare a bound as a constant using #define


identifier. So that the time required to modify the size will be minimized in case of
complex programs.

Algorithm
1.
2.
3.
4.
5.
6.

Read the number of elements in an array (n).


Initialize the iterative value (i) as zero.
Repeat the steps 4 and 5 until no. of values minus 1 (n-1).
Read the elements of an array a[i].
Increment the iterative value.
Display the elements from the last position of an array to first position of an array.

Flowchart

Start

reverse

Stop

reverse

Read total no. of


elements

Repeat the process until n1

Read the array elements


a[i]
Next
i
Repeat the loop i
from n-1 to 0

Display the array


elements
Decrement
i
Stop
Program
#include<stdio.h>
#include<conio.h>
void reverse();
int n,i,a[10];
void main()
{
reverse();
}
void reverse()
{
int n,i;
clrscr();
printf("Enter the total number of elements");
scanf("%d",&n);
printf("Enter the elements:\n");
for(i=0;i<n;i++)
{

scanf("%d",&a[i]);
}
printf("Reversed elements are:\n");
for(i=n-1;i>=0;i--)
{
printf("%d\n",a[i]);
}
getch();
}
Sample Input and Output:
INPUT:
Enter the total number of elements
5
Enter the Elements:
12
34
56
78
90
OUTPUT:
Reversed elements are:
90
78
56
34
12

Result
Thus all the elements of an array are displayed in reverse order.

EX.NO.:18

MATRIX ADDITION AND MULTIPLICATION

Aim
Implement Matrix addition and Multiplication using an array
Algorithm
Matrix Addition:
1. Read the total number of rows & columns for the matrix
2. Read the elements for A Matrix and store it into two dimensional arrays.
3. Read the elements for B Matrix and store it into other two dimensional array.
4. Add the elements of 2 matrixes namely A & B through the nested for Loops and
store the result into a resultant 2-dimesional array C.
5. Display the result
Matrix Multiplication:
1. Read the total number of rows & columns for the matrix
2. Read the elements for A Matrix and store it into two dimensional arrays.
3. Read the elements for B Matrix and store it into other two dimensional array.
4. Multiply the elements of 2 matrixes namely A & B through the nested for Loops
and store the result into a resultant 2-dimesional array C.
5. Display the result

Flowchart

Matrix Addition

Start

Read the rows & columns for the


matrixes A & B

Read the elements for the Matrix A

Store the elements into a 2-dimensional array for Matrix A


through the nested for loops

Read the elements for the Matrix B

Store the elements into a 2-dimensional array for Matrix B


through the nested for loops

Display the elements of 2 Matrixes A & B through the


nested for loops

Add the elements of 2 Matrixes A & B through the nested


for loops and store the result in a resultant 2-dimensional
array C

Display the result through the nested for loops

Stop

Matrix Multiplication

Start

Read the rows & columns for the


matrixes A & B

Read the elements for the Matrix A

Store the elements into a 2-dimensional array for Matrix A


through the nested for loops

Read the elements for the Matrix B

Store the elements into a 2-dimensional array for Matrix B


through the nested for loops

Display the elements of 2 Matrixes A & B through the


nested for loops

Add the elements of 2 Matrixes A & B through the nested


for loops and store the result in a resultant 2-dimensional
array C

Display the result through the nested for loops

Stop

Program
1. Matrix Addition
#include<stdio.h>
#include<conio.h>
int a[25][25],b[25][25],c[25][25],m,n,i,j;
void main()
{
clrscr();
printf("Enter the rows and columns of two matrixes\n");
scanf("%d %d",&m,&n);
printf("Enter the elements of A matrix\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("Enter the elements of B matrix\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&b[i][j]);
}
}
printf("Elements of A matrix are:\n");
for(i=0;i<m;i++)
{
printf("\n");
for(j=0;j<n;j++)
{
printf("\t%d",a[i][j]);
}
}
printf("\nElements of B matrix are:\n");
for(i=0;i<m;i++)
{
printf("\n");
for(j=0;j<n;j++)
{
printf("\t%d",b[i][j]);
}
}

printf("\nThe addition of 2 matrixes are:\n");


for(i=0;i<m;i++)
{
printf("\n");
for(j=0;j<n;j++)
{
c[i][j]=a[i][j]+b[i][j];
printf("\t%d",c[i][j]);
}
}
getch();
}

2. Matrix Multiplication
#include<stdio.h>
#include<conio.h>
int a[25][25],b[25][25],c[25][25],m,n,i,j,k;
void main()
{
clrscr();
printf("Enter the rows and columns of two matrixes\n");
scanf("%d %d",&m,&n);
printf("Enter the elements of A matrix\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("Enter the elements of B matrix\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&b[i][j]);
}
}
printf("Elements of A matrix are:\n");
for(i=0;i<m;i++)
{
printf("\n");
for(j=0;j<n;j++)
{
printf("\t%d",a[i][j]);
}
}
printf("\nElements of B matrix are:\n");

for(i=0;i<m;i++)
{
printf("\n");
for(j=0;j<n;j++)
{
printf("\t%d",b[i][j]);
}
}
for(i=0;i<m;i++)
{
printf("\n");
for(j=0;j<n;j++)
{
c[i][j]=0;
for(k=0;k<m;k++)
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
}
printf("\nThe Multiplication of 2 matrixes are:\n");
for(i=0;i<m;i++)
{
printf("\n");
for(j=0;j<n;j++)
{
printf("\t%d",c[i][j]);
}
}
getch();
}
Sample Input and Output:
Matrix Addition
INPUT:
Enter the rows and columns of two matrixes
3
3
Enter the elements of A matrix
1
2
3
4
5
6
7
8
9
Enter the elements of B matrix
1
2

3
4
5
6
7
8
9
OUTPUT:
Elements of A matrix are:
1
4
7

2
5
8

3
6
9

Elements of B matrix are:


1
2
3
4
5
6
7
8
9
The addition of 2 matrixe are:
2
8
14

4
10
16

6
12
18

Matrix Multiplication
INPUT:
Enter the rows and columns of two matrixes
3
3
Enter the elements of A matrix
1
2
3
4
5
6
7
8
9
Enter the elements of B matrix
1
2
3
4
5
6

7
8
9
OUTPUT:
Elements of A matrix are:
1
2
3
4
5
6
7
8
9
Elements of B matrix are:
1
4
7

2
5
8

3
6
9

The Multiplication of 2 matrixes are:


30
66
102

36
42
81
96
126 150

Result
Thus Matrix addition and Multiplication using an array was implemented
successfully.

STRING MANIPULATIONS
The C compiler provides the following string handling functions:
Function

Purpose

strlen()

Used to find the length of the string

strcpy()

Used to copy one string to another

strcat()

Used to combine two strings

strcmp()

Used to compare characters of two strings (difference between


small and capital letters)

strlwr()

Used to convert strings into lower case

strupr()

Used to convert strings into upper case

strdup()

Used to duplicate a string

strrev()

Used to reverse a string

Strncpy()

Used to copy first n characters of one string to another

Strncmp()

Used to compare first n characters of two strings.

Strcmpi()

Used to compare two strings without regarding the case.

strnicmp()

Used to compare first n characters of two strings without


regarding the case.

Stricmp()

Compares two strings (Not difference between small and capital


letters)

strchr()

Determines first occurrence of a given character in a string.

strrchr()

Determines last occurrence of a given character in a string.

strstr()

Determines first occurrence of a given string in another string

strncat()

Appends source string to destination string upto specified length.

strnset()

Sets specified number of characters of string with a given


argument or symbol.

strspn()

Finds upto what length two strings are identical.

strpbrk()

Searches the first occurrence of the character in a given string and


then it displays the string starting from that character.

EX.NO.:19

MANIPULATION OF STRING FUNCTIONS

Aim
To write a C program to implement string functions without using library functions.
COMPUTING
Start STRING LENGTH
Algorithm:
1. Read the String (str). Read the String
2. Initialize a counter variable len as zero.
3. Increment the counter variable until the null character of string is reached.
Initialize length as zero
4. Print the length of the string (len).
Flow chart:
Repeat the process until
null character is reached

Increment the length

Display the length of the String

Stop

Program
#include<stdio.h>
#include<conio.h>
void main()
{
char str[50];
int len;
clrscr();
printf("Enter the string:");
scanf("%s",str);
for(len=0;str[len]!='\0';len++);
printf("Length of string is %d\n",len);
getch();
}
INPUT:
Enter the string: psnacollege
OUTPUT:
Length of string is 11
STRING COMPARISON
Algorithm

1. Read two Strings (str1, str2).


2. Compute the length of the two strings and store it in len1, len2 respectively.
3. If the length of two strings are equal
a. Initialize counter value (i) as 1 and (j) as 0.
b. Repeat the steps 3.c to 3.e until the length of the strings.
c. Check each character of the strings.
d. If they are same
Start variable j.
i. Increment the counter
e. Increment the counter variable i
4. If the j value is same as the length of the String
Display both
thetwo
Strings
are namely
Equal. str1, str2
Read
Strings
5. Else
Displays both the Strings are not equal.
Compute the length of the two strings len1, len2

If the
lengths are
equal
Y
Flow chart

Compare each character of the two strings

If they
are
same
Increment the counter variable j

If j value is
equal to length
of the string

Y
Display Both
the Strings
are Equal

Stop

Display Both
the Strings are
Unequal

Program
#include<stdio.h>
#include<conio.h>
void main()
{
char str1[20],str2[20];
int i,j=0,len1,len2;
clrscr();
printf("Enter the two strings:");
scanf("%s%s",str1,str2);
for(len1=0;str1[len1]!='\0';len1++);
for(len2=0;str2[len2]!='\0';len2++);
if(len1==len2)
{
for(i=1;i<=len1;i++)
{
if(str1[i]==str2[i])
j+=1;
}
}
if(j==len2)
printf("Both strings are equal");
else
printf("Both strings are not equal");
getch();

}
INPUT:
Enter the two strings: apple apple
Both strings are equal
OUTPUT:
Enter the two strings: boy ball
Both strings are not equal.
COPYING THE STRING
Algorithm
1. Read the String (str1).
2. Initialize a counter variable (i) as zero.
3. Repeat the steps 4 and 5 until the null character of string is reached.
4. Copy each character from string1 to another string (str2).
5. Increment the counter variable.
Start
6. Add the null character to the end of the String (str2).
7. Display the copied String (str2).
Read the String (str1)
Flow chart
Initialize length as zero

Repeat the process until


null character is reached
Copy each character from string1 to String 2

Increment the length

Add the null character to the end of the String2

Display the Copied String(str2)

Stop

Program
#include<stdio.h>
#include<conio.h>
void main()
{
char str1[20],str2[20];
int i,j;
clrscr();
printf("Enter the first string:");
scanf("%s",str1);
printf("\nThe first string is %s",str1);
for(i=0;str1[i]!='\0';i++)
{
str2[i]=str1[i];
}
str2[i]='\0';
printf("\nCopy the string without using strcpy() function");
printf("\nThe Copied String is %s",str2);
getch();
}

INPUT:
Enter the first String: India
OUTPUT:
The First string is India
Copy the string without using strcpy() function
The Copied String is India
STRING CONCATENATION
Algorithm
1. Read two Strings (str1,str2).

2. Copy each character from string1 to another string (str3) until the null character of
string1 is reached.
3. Continuously copy each character from string2 to string (str3) until the null
character of string2 is reached.
4. Add the null character to the end of the String (str3).
5. Display the concatenated String (str3).

Flow chart
Start

Read two strings str1,str2

Copy each character from string (str1) to String (str3)

Continuously copy each character from string (str2) to String (str3)

Display the Concatenated String (str3)

Stop

Program
#include<stdio.h>
#include<conio.h>
void main()
{
char str1[10],str2[10],str3[10];
int i,j;
clrscr();
printf("Enter the two string:");
scanf("%s%s",str1,str2);
for(i=0;str1[i]!='\0';i++)
{
str3[i]=str1[i];
}
for(j=0;str2[j]!='\0';j++)
{
str3[i]=str2[j];
i++;
}
str3[i]='\0';
printf("Concatenated String is.....%s\n",str3);
getch();
}
INPUT:
Enter the two string: Anna

University

OUTPUT:
Concatenated string is. AnnaUniversity

RESULT:
Thus the string manipulation functions are executed successfully without using
library functions.
EX.NO.:20

ARRANGING NAMES IN ALPHABETICAL ORDER

Aim
To write a C program to arrange the names in alphabetical order.
Algorithm
1 .Read the number of names (n) to be sorted.
2. Read the names in an array names[i].
3. Increment the iterative value.
4. Initialize the iterative value (i) to 0.
5. Repeat the steps 7 to 11 until the number of values minus 1 (n-1).
6. Assign the iterative value j as i+1.
7. Repeat the steps 9 - 10 until iterative value (j) less than no. of values (n).
8. Compare the Strings as
If names[i], names[j]>0 then
Swap the names using temporary variable by using the strcpy() function.
9. Increment the iterative value (j)

10. Increment the iterative value (i)


11. Display the names in the sorted order.
Flow chart

Start
Sta
Read the number of values (n)
Read the elements in an array
names[i]

Compare the Strings using strcmp() function

If the value is
greater than 0

Swap the names using temporary


variable using strcpy() function

Display the sorted names

stop

Program
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char names[50],temp[20];
int n,i,j;

clrscr();
printf("\n How many names are there to sort?:");
scanf("%d",&n);
printf("\n Enter the %d names one by one\n",n);
for(i=0;i<n;i++)
scanf("%s",names[i]);
for(i=0;i<n-1;i++)
for(j=i+1;j<n;j++)
if(strcmp(names[i],names[j])>0)
{
strcpy(temp,names[i]);
strcpy(names[i],names[j]);
strcpy(names[j],temp);
}
printf("\n Names in alphabetical order are:");
for(i=0;i<n;i++)
printf("\n %s",names[i]);
getch();
}
Sample Input and Output:
INPUT:
How many names are there to sort?
5
Enter the 5 names one by one
India
Asia
Nepal
Srilanka
Bhutan
OUTPUT:
Names in alphabetical order are:
Aravind
Banu
Priya
Sakthi
Yamuna
Result
Thus the C program to arrange the given string in alphabetical order executed
successfully.

FUNCTIONS
A function is meant for performing a specified task. The specified task is repeated
each time the program calls the functions. Functions break large computing tasks in to
smaller ones. They work together to accomplish the goal f the whole program. Every
program must contain one function named main where the program always begins
execution.
The main function may call other functions which in turn, may call still other
functions. When a function is called, the program execution is transferred to the first
statement in the called function. After a function returns to the calling function, execution
continues with the evaluation of the expression in which the call was made. A value can
be returned when a function completes the specified task and that value can be used as an
operand in an expression.
Functions can communicate data between themselves in two ways. One through
global variables and other through an argument or parameter list.
Function definition
A function definition introduces a new function by declaring the type of value it
returns and its parameters, and specifying the statements that are executed when the
function is called. Consider the following example,
#include<stdio.h>
main()
{
printline();
printf(This illustrates the usage of functions\n);
printline();
}
/*the statement defines a function called printline, which prints a line of 40
characters. This function has been called from the main().*/
Printline()
{
int i;
for(i=0;i<=40;i++)
printf(-);
}
The function in which call is continued is known as the calling function and the
function named in the call is said to be the called function. In the above example main()
is the calling function and printline() is the called function. The function printline()
returns no value (void). When a function is required to return a value, the return type has
to be specified explicitly. The general form of C function is give below
function_name(argument list)
argument declaration;
{
Variable declaration;
Function statements;
}
Arguments

Consider the simple example given below


main()
{
int num1=3, num2=334, sum;
sum=num1+num2;
printf(The sum of two numbers is %d\n, sum);
}
When the printf function is called, one or more values are supplied to this function, the
first value being the format string and the remaining values the specific program results to
be displayed. These values, called arguments, greatly increase the flexibility of a
function.
For example, a function such as one given below, can be defined.
Copy(name1, name2)
Here, copy is a user defined function name, which accepts two arguments name1 and
name2 respectively.

EX.MO.:21

IMPLEMENTING SEQUENTIAL SEARCH USING FUNCTION

Aim:
To write a program to perform sequential search using functions.
Algorithm:
1. Read the number of elements in an array(n).
2. Read the elements of an array using for loop.
3. Read the element to be searched in the array (k)
4. Call the function search() by passing the array, element to be searched, total
no of elements as arguments.
5. Compare each & every element of the array with k.
6. If it matches,
Print as element found
Else
Print as element not found.

Flowchart
Start

Read the total number of elements

Read the elements of an array

Read the element to be searched


in the array(k)

Search (array [], k,


n)

Stop

Search (array [], k,


n)
Compare every element of an array with the
element to be searched

If
found
Y
Display the
element is found

Return

Display the element


is not found

Program
#include<stdio.h>
#include<conio.h>
void search(int a[],int,int);
void main()
{
int a[100],i,j,n,k;
char c='y';
clrscr();
printf("\n Sequential Search\n");
printf("\n Enter total no of elements in the array");
scanf("%d",&n);
printf("\n Enter the elements one by one");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
while(c=='y' || c=='Y')
{
printf("\n Enter the element to be searched");
scanf("%d",&k);
search(a,k,n);
printf("\nDo you want to continue(y/n)?");
c=getch();
}
getch();
}
void search(int a[],int k,int n)
{
int i;
int f=1;
for(i=0;i<n;i++)
{
if(a[i]==k)
f=2;
}
if (f==2)
printf("\n Element Found");
else
printf("\n Element not found");
}

Sample Input and Output:


INPUT:
Sequential Search
Enter total no of elements in the array 5
Enter the elements one by one 10 20 30 40 50
Enter the element to be searched 50
OUTPUT:
Element Found
Do you want to continue(y/n)? y
Enter the element to be searched 5
Element Not Found
Do you want to continue(y/n)? n

Result
Thus the program for the sequential and binary search is performed.

RECURSIVE FUNCTIONS
A recursive function is one which calls itself. This is another complicated idea
which you are unlikely to meet frequently. We shall provide some examples to illustrate
recursive functions.
Recursive functions are useful in evaluating certain types of mathematical
function. You may also encounter certain dynamic data structures such as linked lists or
binary trees. Recursion is a very useful way of creating and accessing these structures.
Here is a recursive version of the Fibonacci function. .
int fib(int num)
/* Fibonacci value of a number */
{
switch(num) {
case 0:
return(0);
break;
case 1:
return(1);
break;
default: /* Including recursive calls */
return(fib(num - 1) + fib(num - 2));
break;
}
}
Here is an another example to find power using recursive version.
double power(double val, unsigned pow)
{
if(pow == 0) /* pow(x, 0) returns 1 */
return(1.0);
else
return(power(val, pow - 1) * val);
}
Notice that each of these definitions incorporates a test. Where an input value
gives a trivial result, it is returned directly; otherwise the function calls itself, passing a
changed version of the input values. Care must be taken to define functions which will
not call themselves indefinitely, otherwise your program will never finish.
Don't be frightened by the apparent complexity of recursion. Recursive functions
are sometimes the simplest answer to a calculation. However there is always an
alternative non-recursive solution available too. This will normally involve the use of a
loop, and may lack the elegance of the recursive solution

EX.NO.:22

FINDING THE FACTORIAL USING RECURSION

Aim:
To write a C program to calculate the factorial of the given number using
recursive functions.
Algorithm
1. Read the number (a)
2. Call the function rec() by passing the number
3. If the number is 0
Return the factorial value as 1.
4. Else
Compute the factorial value by recursively calling rec() function by
decrementing the number (x).
5. Return the factorial value (f).
6. Display the factorial value.

Flowchart
Start

Read the number


a
recursive(a)

Display the Factorial Value

Stop

recursive(a)

Y
If the
value is 0

Factorial value is 1

N
Compute factorial value as
F=f*rec(a-1)

Return the factorial value

Program:
#include<stdio.h>
#include<conio.h>
int recursive(int);
void main ()
{
int a,fact;
clrscr();
printf("Enter the number:");
scanf("%u",&a);
fact=recursive(a);
printf("The factorial of %u is %u",a,fact);
getch();
}
int recursive(x)
int x;
{
int f;
if(x==0)
return(1);
else
f=x*recursive(x-1);
return(f);
}
Sample Input and Output:
INPUT:
Enter the number 5
OUTPUT:
The factorial of 5 is 120

Result
Thus the program for the factorial using recursive function is performed.

STRUCTURES IN C
A structure is a collection of variables under a single name. These variables can be
of different types, and each has a name which is used to select it from the structure. A
structure is a convenient way of grouping several pieces of related information together.
Accessing Members of a Structure
Each member of a structure can be used just like a normal variable, but its name
will be a bit longer.
st_rec.name

Here the dot is an operator which selects a member from a structure.


Where we have a pointer to a structure we could dereference the pointer and then use dot
as a member selector. This method is a little clumsy to type. Since selecting a member
from a structure pointer happens frequently, it has its own operator -> which acts as
follows. Assume that st_ptr is a pointer to a structure of type student We would refer to
the name member as
st_ptr -> name
For and While Loops
Defining For-Loops:
C uses two types of loops: for and while. It has four distinct sections as shown below:
initialization, condition, iteration and body. The first three sections, follow the for
keyword and are enclosed in parentheses. The sections must be divided by semi-colons,
even when one or more of the sections are empty. The body of the loop follows and is
enclosed in braces - except when there is only one statement in the body, when the braces
are optional.
for (INITIALIZATION; CONDITION; ITERATION)
{
BODY
}
A simple example of a for-loop initializes each member in an array.
int month[12], i;
for (i = 0; i < 12; i++)
{
month[i] = 0;
}
Condition Section;
The condition section describes what must be true for the loop body to be
performed again. When the condition becomes not true, control passes to the statement
after the for-loop. The condition section can be left empty, but then there must be code in
the body to break out of the loop when some condition is met, or the loop will execute for
ever.

The condition section is evaluated according to the normal Boolean laws of C.


Evaluation of the condition, going from left to right, will stop as soon as it can be
determined that the whole condition is certainly true or false. In the example below, if it is
greater than or equal to 10, then the value in table[i] is not checked.
int i, table[10];
for (INITIALIZATION; i < sizeof(table) && table[i] != 0; ITERATION)
{
BODY
}
If the condition evaluates to false the first time it is tested, the body of the loop will not be
performed at all and neither will the iteration.
Iteration Section:
The iteration statements are performed each time the body of the loop completes,
before the condition is tested again. If there is more than one statement in the iteration
section, you should separate them by commas and they will be performed in order from
left to right.
In this example, the counter is incremented on each iteration, but only after the current
value in the table has been added to the total.
int i, total, table[10];
for (INITIALIZATION; CONDITION; total += table[i], i++)
{
BODY
}
The iteration section can be left empty if there is nothing to do after each loop.
Body:
The statements in the body of the loop must be enclosed in braces if there is more
than one statement: otherwise they are optional. If the body is empty, you must code
either empty braces or a semi-colon to end the for-statement.
for (INITIALIZATION; CONDITION; ITERATION)
{
}
Comparing For-Loops and While-Loops:
For-loops can be rewritten as while-loops by moving the initialization and
iteration sections as shown below. Or, to put it another way, a while-loop is like a for-loop
with no initialization or iteration sections.
INITIALIZATION
while (CONDITION)
{
BODY
ITERATION
}

EX.NO.:23

PREPARING MARK LIST USING STRUCTURES CONCEPT

Aim
To write a program in C to print the mark sheet of n students using structure.
Algorithm
1. Initialize the structure student with its members like name, number, marks, total,
average and grade.
2. Read the number of students (n).
3. Read the student number, name and six subject marks for n students.
4. Find the total marks and average for each student.
5. Award the grade for each student by checking the marks of all the subjects.
6. Print the student mark list displaying the student number, name, total marks,
average and grade for each student.

Flowchart

Start
Initialize the structure student with its
members like name, number, marks,
total, average and grade

Read the number of students (n)

Read the student number,


name and six subject marks
Find the total marks and average
for each student

If at least one of
the marks is less
than 35

Grade = Fail

N
Y

If
avg>=75

Grade = Distinction

N
Y

If avg <75
& >=60

Grade = first class

N
Y

If avg <60
& >=50
N

Display the Marklist for all the Students

B Stop

Grade = Second class

Program
#include<string.h>
#include<stdio.h>
#include<conio.h>
struct student
{
int sno,m1,m2,m3,m4,m5,m6,tot;
char name[10],grade[50];
float avg;
}s[10];
void main()
{
float avg;
int tot,n,i;
clrscr();
printf("Enter the number of students to process..");
scanf("%d",&n);
printf("Enter Student number, name and 6 subject marks ...\n");
for(i=1;i<=n;i++)
{
scanf("%d%s%d%d%d%d%d
%d",&s[i].sno,&s[i].name,&s[i].m1,&s[i].m2,&s[i].m3,&s[i].m4,&s[i].m5
,&s[i].m6);
s[i].tot=s[i].m1+s[i].m2+s[i].m3+s[i].m4+s[i].m5+s[i].m6;
s[i].avg=s[i].tot/6;
if(s[i].m1<35||s[i].m2<35||s[i].m3<35||s[i].m4<35||s[i].m5<35||s[i].m6<35)
strcpy(s[i].grade,"Fail");
else
{
if(s[i].avg>=75)
strcpy(s[i].grade,"Distinction");
else if(s[i].avg<75 && s[i].avg>=60)
strcpy(s[i].grade,"First class");
else if(s[i].avg<60 && s[i].avg>=50)
strcpy(s[i].grade,"Second class");
}
}
printf("Student Mark List \n");
printf("S.No\tSname\tTotal\tAverage\tGrade\n");
printf("-------------------------------------------------\n");
for(i=1;i<=n;i++)
{
printf("%d\t%s\t%d\t%f\t%s",s[i].sno,s[i].name,s[i].tot,s[i].avg,s[i].grade);
printf("\n");
}
getch();
}

Sample Input and Output


INPUT:
Enter the number of students to process..
2
Enter Student number, name and 6 subject marks...
100
aravind
96
78
85
76
99
86
101
Brinda
72
64
60
77
32
62
OUTPUT:
Student Mark List
S.No Sname
Total
Average
Grade
-----------------------------------------------------------------------------100 aravind
520
86.000
Distinction
101 brinda
367
61.16
Fail

Result
Thus the program to print the mark sheet of n students using structure is written
and executed.

EX.NO.:24

FINDING THE STRING LENGTH USING POINTERS

Aim
To write a C program to find the length of the string using pointers.
Algorithm
1. Read the String(ptr)
2. Initialize the variable (len) as 0.
3. The ptr value refers to the address of the first character of the string and the
*ptr refers to the actual string.
4. Till the string(*ptr) exist
a) Increment the length
b) Increment the pointer variable(ptr)
5. Display the length of the string
Flowchart
Start

Read the String (ptr)

Till the
String
exists
(*ptr)

Increment the value of len and ptr

Print the string


length

Stop

Program
#include<stdio.h>
#include<conio.h>
void main()
{
char *ptr;
int len=0;
clrscr();
printf("Enter the String : ");
scanf("%s",ptr);
while(*ptr)
{
++len;
++ptr;
}
printf("Length of the string : %d",len);
getch();
}

Sample Input and Output


Input
Enter the String: college
Output
Length of the string: 7

Result
Thus the program for finding the string length using pointers is executed.

EX.NO.:25

PRINTING THE ARRAY ELEMENTS USING POINTERS

Aim
To write a C program to print the elements of an array using pointers.
Algorithm
1.
2.
3.
4.
5.
6.
7.

Read the number of elements (n).


Initialize the iterative value (i) as zero.
Repeat the steps 4 and 5 until no. of values minus 1 (n-1).
Read the elements of an array (a [i]).
Increment the iterative value.
Assign the address of an array to the pointer variable (ptr).
Print the elements of an array using the pointer variable (*ptr).

Flowchart
Start

Read total no. of


elements (n)

Repeat the process until n1

Read the array elements


a[i]
Next
i
Assign the address of an array to a
pointer variable (ptr)
Display the array elements
using pointers (*ptr)

Stop

Program
#include<stdio.h>
#include<conio.h>
void main()
{
int a[20],*ptr,i,n;
clrscr();
printf("\n Enter total number of elements:");
scanf("%d",&n);
printf("\n Enter elements");
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
ptr=a;
printf("\nArray elements\n");
for(i=1;i<=n;i++)
printf("%d\n",*(ptr+i));
getch();
}

Sample Input and Output


INPUT:
Enter total number of elements:
5
Enter elements
5
4
3
2
1
OUTPUT:
Array elements
5
4
3
2
1
Result

Thus the program for printing the elements of an array using pointers is
written and executed.
EX.NO.:26
STUDENT MARK STATEMENT USING FILE CONCEPT
Aim
To write a C program to prepare student mark statement using file concept.
Algorithm
1. Initialize the structure student with its members like name, number, marks, total,
average and grade.
2. Read the number of students (n).
3. Create a new file in write mode to store the student mark statement details.
4. Read the student number, name and marks for n students.
5. Find the total marks and average for each student.
6. Print the student mark statement displaying the student number, name, total marks
and average for each student in the output file.
Flowchart
Start
Initialize the structure student with its
members like name, number, marks,
total and average

Create a new file in write mode


(students.c)

Read the number of students (n)

Read the student number,


name and three subject marks
Find the total marks and average
for each student
Display the Mark statement
for each student
Write the Mark statement for all the
Students in the Output File

Stop

Program
#include<stdio.h>
#include<conio.h>
struct student
{
char name[20];
int rn;
int m1,m2,m3,total,avg;
}s[10];
void main()
{
FILE *fp;
int n,i;
clrscr();
fp=fopen("students.c","w");
printf("\n Enter the no. of students:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\n Enter the name:");
scanf("%s",s[i].name);
printf("\n Enter the no.:");
scanf("%d",&s[i].rn);
printf("\n Enter the Mark m1:");
scanf("%d",&s[i].m1);
printf("\n Enter the Mark m2:");
scanf("%d",&s[i].m2);
printf("\n Enter the Mark m3:");
scanf("%d",&s[i].m3);
fprintf(stdout,"\n Name =%s",s[i].name);
fprintf(stdout,"\n Number =%d",s[i].rn);
fprintf(stdout,"\n Mark1 =%d",s[i].m1);
fprintf(stdout,"\n Mark2 =%d",s[i].m2);
fprintf(stdout,"\n Mark3 =%d",s[i].m3);
s[i].total=s[i].m1+s[i].m2+s[i].m3;
fprintf(stdout,"\n Total =%d",s[i].total);
s[i].avg=s[i].total/3;
fprintf(stdout,"\n Average =%d",s[i].avg);
fprintf(fp,"\n Name =%s",s[i].name);
fprintf(fp,"\n Number =%d",s[i].rn);
fprintf(fp,"\n Mark1 =%d",s[i].m1);
fprintf(fp,"\n Mark2 =%d",s[i].m2);
fprintf(fp,"\n Mark3 =%d",s[i].m3);
fprintf(fp,"\n Total =%d",s[i].total);
fprintf(fp,"\n Average =%d",s[i].avg);
}
fclose(fp);

getch();
}
Sample Input and Output
INPUT:
Enter the no. of students: 2
Enter the name:keerthi
Enter the no.:12
Enter the Mark m1:89
Enter the Mark m2:65
Enter the Mark m3:54
Name =keerthi
Number =12
Mark1 =89
Mark2 =65
Mark3 =54
Total =208
Average =69
Enter the name:kamala
Enter the no.:45
Enter the Mark m1:56
Enter the Mark m2:34
Enter the Mark m3:98
Name =kamala
Number =45
Mark1 =56
Mark2 =34
Mark3 =98
Total =188
Average =62
OUTPUT:
Students.c:
Name =keerthi
Number =12
Mark1 =89
Mark2 =65
Mark3 =54
Total =208
Average =69
Name =kamala
Number =45
Mark1 =56
Mark2 =34
Mark3 =98
Total =188
Average =62
Result

Thus the program for student mark statement using file concept is written
and executed.
EX.NO.:27

MERGING OF TWO FILES USING


COMMAND LINE ARGUMENTS

Aim
To write a C program to merge two files using command line arguments.
Algorithm
1. Read the input as 3 file names in the command line arguments.
2. Open the first two files in read mode & third file in write mode.
3. Get the characters one by one from the first file and put it in the third file using
file pointer until EOF (End of File) has been reached
4. Get the characters one by one from the second file and appended it with the
third file until EOF has been reached.
5. Display the content of the Output (third) file.

Flowchart
Start

Read the input as 3 file names in


the command line arguments.

Open the first two files in read mode &


third file in write mode.

Till not
EOF of
file1
Y

Get the characters one by one from the first


file and put it in the third file

Till not
EOF of
file2
Y

Get the characters one by one from the


second file and append it to the third file

Display the contents of the


output file

Stop

Program
#include <stdio.h>
#include<conio.h>
void main(int argc,char *argv[])
{
FILE *fp1, *fp2,*fp3;
int c,c1 ;
if(argc==4)
{
fp1 = fopen( argv[1], "r" );
fp2 = fopen( argv[2],"r" ) ;
fp3=fopen(argv[3],"w+");
}
else
{
printf("error");
}
c= getc(fp1) ;
c1=getc(fp2);
while (c != EOF)
{
putc(c,fp3);
c= getc( fp1) ;
}
while(c1!=EOF)
{
putc(c1,fp3);
c1=getc(fp2);
}
fclose ( fp1 );
fclose ( fp2 );
fclose(fp3);
printf("Files successfully merged \n");
getch();
}

Sample Input and Output


INPUT:
C:\tc\bin> prog1.c prog2.c new.txt
prog1.c :
Welcome to PSNACET
prog2.c :
Dindigul.
OUTPUT:
new.txt :
Welcome to PSNACET
Dindigul.

Result

Thus the program to merge two files using command line arguments is executed
successfully.
Extra Experiments (University Questions)
1. Find Area of the Circle
2. Convert Centigrade to Fahrenheit
3. Find Biggest among three numbers
4. Check the given year is leap year or not
5. Find the sum of row and column of the given matrix
6. Find the sum of digits of the given number
7. Check the given number is Armstrong number or not
8. Print the given number in Reverse order
9. Check the given string is palindrome or not
10. Find the Factorial value of given number using Recursive function
11. Sort the given number in Ascending order
12. Find the transpose of the given matrix
13. Generate the following triangle
1
123
12345
1234567
14. Generate the following triangle
5
5 5
5 5 5
5 5 5 5
15. Find the roots of given quadratic equation
16. Find the sum of the given series
1 - x2/2! x4/4! - . xn/n!
17. Find the largest element in row and column of the given matrix
18. Find the sum of ODD and EVEN position numbers of the given array
19. Find NCr
20. Print student total marks and grade using UNION
21. Swap two numbers without using temporary
22. Check the given number is ODD or EVEN

23. Find the area and circumference of the circle


24. Add two numbers using function
1 ./* Area of Circle */
#include<stdio.h>
#include<conio.h>
void main()
{
int r=0;
clrscr();
printf("Enter the radious :");
scanf("%d",&r);
printf("\n The Area of Circle :
%f",3.14*r*r);
getch();
}
2./* Centigrade to Fahrenheit */
#include<stdio.h>
#include<conio.h>
void main()
{
int c=0;
float f;
clrscr();
printf("Enter the Temperature in
centigrade :");
scanf("%d",&c);
f=32+c*9/5;
printf("\n The Temperture in Farenheat
%f",f);
getch();
}
3./* Biggest of three numbers */
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf("Enter Three Numbers :");
scanf("%d %d %d",&a,&b,&c);
if(a>=b && a>=c)

printf("\n The greatest number is


%d",a);
else if(b>=a && b>=c)
printf("\n The greatest number is
%d",b);
else
printf("\n The greatest number is
%d",c);
getch();
}
4./* Leap Year or Not */
#include<stdio.h>
#include<conio.h>
void main()
{
int a;
clrscr();
printf("Enter The Year:");
scanf("%d",&a);
if(a%4==0)
printf("\n Leap Year");
else
printf("Not a Leap year");
getch();
}
5. /*Row sum and column sum */
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,r,c,rs=0,cs=0;
int m[10][10];
clrscr();
printf("Enter no of row and column :");
scanf("%d %d",&r,&c);
for(i=0;i<r;i++)
for(j=0;j<c;j++)
scanf("%d",&m[i][j]);
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)

rs=rs+m[i][j];
printf("\nSum of Row %d =
%d",i+1,rs);
rs=0;
}
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
cs=cs+m[j][i];
printf("\nSum of Column %d =
%d",j+1,cs);
cs=0;
}
getch();
}
6./* sum of digits */
#include<stdio.h>
#include<conio.h>
void main()
{
int n,r,s=0;
clrscr();
printf("Enter no :");
scanf("%d" ,&n);
while(n>0)
{
r=n%10;
s=s+r;
n=n/10;
}
printf("\nSum of digits = %d",s);
getch();
}
7. /* Armstrong number */
#include<stdio.h>
#include<conio.h>
void main()
{
int no,n,r,s=0;
clrscr();
printf("Enter no :");
scanf("%d" ,&n);
no=n;
while(n>0)
{

r=n%10;
s=s+r*r*r;
n=n/10;
}
if(no==s)
printf("\n Armstrong Number");
else
printf("\n Not an Armstrong Number");
getch();
}
8./* Reverse the digits */
#include<stdio.h>
#include<conio.h>
void main()
{
int i=0,j,n,r,a[10];
clrscr();
printf("Enter no :");
scanf("%d" ,&n);
while(n>0)
{
r=n%10;
a[i]=r;
i++;
n=n/10;
}
for(j=0;j<i;j++)
printf("%d",a[j]);
getch();
}
9./* String is palindrome or not*/
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char name[10];
int i=0,j,len;
clrscr();
printf("Enter Name :");
scanf("%s" ,name);
len=strlen(name);
for(i=0,j=len-1;i<=j;i++,j--)
if(name[i]!=name[j])

{
printf("Not Palindrome");
getch();
exit(0);
}
printf("Palindrome");
getch();
}
10./* Factorial using recursion */
#include<stdio.h>
#include<conio.h>
int fact(int);
void main()
{
int n,f;
clrscr();
printf("Enter the number:");
scanf("%d",&n);
f=fact(n);
printf("\n The factorial value : %d",f);
getch();
}
int fact(int x)
{
int fac;
if(x==0)
return 1;
else
fac=x*fact(x-1);
return fac;
}
11./* sorting of array */
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,temp,n,a[10];
clrscr();
printf("Enter number of element:");
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);

for(i=0;i<n;i++)
for(j=0;j<n;j++)
if(a[i]<a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
printf("\nThe sorted Array");
for(i=0;i<n;i++)
printf("\n%d",a[i]);
getch();
}

12./* Transpose of Matrix */


#include<stdio.h>
#include<conio.h>
void main()
{
int r,c,i,j,m[10][10];
clrscr();
printf("Enter number of rows and
columns:");
scanf("%d %d",&r,&c);
for(i=0;i<r;i++)
for(j=0;j<c;j++)
scanf("%d",&m[i][j]);
printf("\nThe Transpose matrix");
for(i=0;i<r;i++)
{
printf("\n");
for(j=0;j<c;j++)
printf(" %d",m[j][i]);
}
getch();
}
13./* Generate Triangle
1
123
12345
1 2 3 4 5 6 7 */
#include<stdio.h>
#include<conio.h>

void main()
{
int i,k,j;
clrscr();
for(i=1;i<=7;i=i+2)
{
printf("\n");
for(k=7-i-1;k>0;k--)
printf(" ");
for(j=1;j<=i;j++)
printf(" %d",j);
}
getch();
}

clrscr();
printf("Enter values for a,b,c ");
scanf("%d %d %d",&a,&b,&c);
r1=(-b+sqrt(b*b-4*a*c))/2*a;
r2=(-b-sqrt(b*b-4*a*c))/2*a;
printf("\nRoot 1 : %f",r1);
printf("\nRoot 2 : %f",r2);
getch();
}

14./* Generte Triangle


5
5 5
5 5 5
5 5 5 5 */
#include<stdio.h>
#include<conio.h>
void main()
{
int i,k,j;
clrscr();
for(i=1;i<=4;i++)
{
printf("\n");
for(k=4-i;k>0;k--)
printf(" ");
for(j=1;j<=i;j++)
printf(" 5");
}
getch();
}

int fact(int);
void main()
{
int i,j=0,x,n;
float s=0.0;
clrscr();
printf("Enter values for x and n");
scanf("%d %d",&x,&n);
for(i=2;i<=n;i=i+2)
{
if(j==0)
{s=s-(pow(x,i)/fact(i));
j=1;
}
else
{s=s+(pow(x,i)/fact(i));
j=0;
}
}
printf("\nSum of the series : %f",1-s);
getch();
}

15./* Find the Roots */


#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int a,b,c;
float r1,r2;

16./* Find the sum of the series


1-x2/2! - x4/4! ..... */
#include<stdio.h>
#include<conio.h>
#include<math.h>

int fact(int x)
{
int fac;
if(x==0)
return 1;
else
fac=x*fact(x-1);

return fac;
}
17./* Largest element in ROW and
COLUMN */
#include<stdio.h>
#include<conio.h>
void main()
{
int r,c,i,j,max,m[10][10];
clrscr();
printf("Enter no of rows and columns :
");
scanf("%d %d",&r,&c);
for(i=0;i<r;i++)
for(j=0;j<c;j++)
scanf("%d",&m[i][j]);
for(i=0;i<r;i++)
{
max=0;
for(j=0;j<c;j++)
if(m[i][j]>max)
max=m[i][j];
printf("\nRow %d maximum :
%d",i+1,max);
}
for(i=0;i<r;i++)
{
max=0;
for(j=0;j<c;j++)
if(m[j][i]>max)
max=m[j][i];
printf("\nColumn %d maximum :
%d",i+1,max);
}
getch();
}
18./* Sum of ODD and EVEN Position
Numbers */
#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,es=0,os=0,a[10];
clrscr();

printf("Enter length of the array : ");


scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
if(i%2==0)
es=es+a[i];
else
os=os+a[i];
}
printf("\nSum of ODD position no :
%d",os);
printf("\nSum of EVEN position no :
%d",es);
getch();
}
19./* Ncr */
#include<stdio.h>
#include<conio.h>
int fact(int);
void main()
{
int n,r;
float s;
clrscr();
printf("Enter values for n and r");
scanf("%d %d",&n,&r);
s=fact(n)/(fact(n-r)*fact(r));
printf("\nSum of the series : %f",s);
getch();
}
int fact(int x)
{
int fac;
if(x==0)
return 1;
else
fac=x*fact(x-1);
return fac;
}
20./* UNION */
#include<stdio.h>
#include<conio.h>
union student

{
int regno;
int mark[8];
};
void main()
{
int i,j,tot=0;
float avg;
union student st[2];
clrscr();
printf("Enter regno and 8 marks of 2
students");
for(i=0;i<2;i++)
{
printf("\n Enter the register no ");
scanf("%d",&st[i].regno);
printf("\n Enter 8 marks");
for(j=0;j<8;j++)
{
scanf("%d",&st[i].mark[j]);
tot=tot+st[i].mark[j];
}
printf("\nTotal marks : %d",tot);
avg=tot/8;
printf("\nAverage : %f",avg);
if(tot/8 > 59)
printf("\nGrade : First class");
else
printf("\nGrade : Second class");
tot=0;
getch();
}
}
21./* Swap TWO values without
temporary*/
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("Enter two values a b : ");
scanf("%d %d",&a,&b);
a=a+b;
b=a-b;

a=a-b;
printf("Swaped values : a= %d b=
%d",a,b);
getch();
}
22./* ODD or EVEN */
#include<stdio.h>
#include<conio.h>
void main()
{
int a;
clrscr();
printf("Enter The No:");
scanf("%d",&a);
if(a%2==0)
printf("\n Even Number ");
else
printf("Odd Number ");
getch();
}

23./* AREA and Circumference of


Circle */
#include<stdio.h>
#include<conio.h>
void main()
{
int r;
clrscr();
printf("Enter Theradius:");
scanf("%d",&r);
printf("\n Area of the circle : ,3.14*r*r);
printf("\n Circumference of circle :
,2*3.14*r ");
getch();
}
24./* Function for add two nos */
#include<stdio.h>
#include<conio.h>
int add(int,int);
void main()
{
int a,b;

clrscr();
printf("Enter The Nos a,b:");
scanf("%d %d",&a,&b);
c=add(a,b);
printf("\n Sum of nos : %d ",c);
getch();

}
int add(int x,int y)
{
return x+y;
}

You might also like