Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
LAB MANUAL
SUBJECT: BCPC [CSP-133]
Chandigarh University,
Gharuan (Mohali)
Table of Contents
S.No
Name of Experiment
Page
No.
UNIT-I
1
1-7
8-23
24-31
32-35
36-36
6.3
To add, subtract, multiply, divide using switch
statement.
Programs based on loops and jumping statements.
7.1 To print pyramid for different patterns using for loop.
7.2 To print the table of a given number using while/ do
while loop.
7.3 To print the factorial of a number.
37-39
42-43
44-46
UNIT-III
9
47-50
51-53
12
54-56
Submitted By:
(Lakhindra Kumar)
Roll no. 46 I.Sc. Physical
Date: 2/8/2013
Page 1 of 58
Experiment 1
Title: basics of Keyboard, Mouse, Motherboard, RAM, Hard disk, Different printers.
Objective: Providing basic information so that students become familiar to various
peripheral devices.
CPU: Control Unit: works with the operating system to move data between auxiliary storage
and main memory; and between main memory and the ALU
Arithmetic/Logic Unit (ALU): processes data arithmetically (addition, subtraction,
multiplication, division) or logically (greater than, less than, equal to)
Main Memory: contains both program instructions and the data that is required.
A single machine can have multiple CPUs to share processing tasks (co-processors,
multiprocessing), but each CPU can execute only a single task.
Keyboard: Windows PCs use tow basic types of keyboards that are classified by the number
of keys they have:
101-key Enhanced keyboard
104-key Windows keyboard
The windows keyboard has some extra keys that address windows specific functions
such as opening the start menu or opening the shortcut menu.
Many new style keyboards also include keys or buttons for connecting to the internet,
sending and receiving emails, and adjusting the volume of the sound system separate
software needed to manage them.
Page 2 of 58
Printer:
A computer printer, or more commonly a printer, is a computer peripheral which produces
a hard copy (permanent human-readable text and/or graphics) of documents stored in
electronic form, usually on physical print media such as paper or transparencies. Many printers
are primarily used as local peripherals, and are attached by a printer cable to a computer which
serves as a document source. Some printers, commonly known as network printers, have
built-in network interfaces (typically wireless or Ethernet), and can serve as a hardcopy device
for any user on the network. Individual printers are often designed to support both local and
network connected users at the same time.
Different Types are:
Dot Matrix
Ink jet printer
Laser Printer
Introduction to windows
Windows
The Desktop
The word desktop has been derived from real life desk top were a manager puts all the things
required by her. For instance, on a desktop, there may be pen stand, notepad, calculator, etc.
Lying, which are required by the manager. The desktop of a Windows also serves the same
purpose.
Page 3 of 58
WINDOWS DESKTOP
In Windows Operating System, the screen upon which icons, Windows, etc. are displayed is
known as desktop. The Windows Operating System desktop may contain a background, one
or more active or inactive windows, a taskbar and icons. A background can be anything from
a single- color screen to an elaborate artistic image. All windows and icons are superimposed
on the background, whatever it may be.
The Icons
Icons are the pretty pictures representing Windows elements like files, folders, shortcuts, etc.
Icons play a very important role in graphical user interface.
Page 4 of 58
4. Disk-drive icons: Disk-drive icons graphically represent five disk drive options:
floppy disk, hard-disk, network, Ram, and CD-ROM. The floppy disk,
Hard-disk and CD-ROM icons resemble the faceplates of the disk drives. Typically, PCs
have only one or two floppy drives, assigned to A and B.
The Taskbar
This is bar that is usually found at the bottom of your screen. The start button about which
we have discussed just now is located on the task bar only.
Apart from the start button, the taskbar hosts the clock, some toolbar and the buttons
corresponding to all open windows.
Department of Applied Science
Page 5 of 58
Buttons on the taskbar show you which windows are open, even if some windows are
minimized or hidden beneath another window. You can easily switch to a different window
by clicking its taskbar button. That is, if you are currently working in Microsoft Excels
window and now you want to switch to Microsoft PowerPoint, which is also active in
another window, then, all you need to do is: click the button representing Microsoft
PowerPoint on the taskbar.
Page 6 of 58
Most of the programs on the computer are available one convenient location- the Programs
section of the Start menu. Depending on how your computer is set up, what you see on the
Start menu varies.
To start a program
(MS Paint located on Accessories Group)
1. Click the start button, and then point to programs. The programs sub-menu appears.
2. Point to the group such as Accessories here that contains the program you want to start
and then click the program name i.e., on MSPaint in our case.
MINIMIZE:
It
is
used
to
minimize
a
window.
minimized window is still open, and a window button appears on the taskbar.
RESTORE: Return a window to its previous size i.e., the original size in which it
was opened.
Page 7 of 58
This is used to change the settings of your computer. When you click on the Control Panel on
Task bar windows showing the contents of it appears.
Conclusion: Students are made familiar with various I/O devices and components of CPU
through the demonstration and with the windows operating system, its icons and menus and
Control Panel through the working.
Page 8 of 58
Experiment 2
Title: Practice with MS Word, Operating and closing document, Preparation of document,
setting of document, familiarization with various tools, mail- merge practice.
Objective: To understand the Word in depth like creating, editing, formatting and printing
the documents and to understand its good tools like Mail merge
Two Ways
1. Double click on the Microsoft Word icon on the desktop.
2. Click on Start --> Programs --> Microsoft Word
Page 9 of 58
Toolbars
Formatting
Editing
Shortcuts
Page 10 of 58
Page 11 of 58
The Menu bar: This toolbar is constructed of word commands and not icons (pictures).
The Menu bar contains all the options available to you in Microsoft Word. Using this toolbar
to format and change your document will often allow you greater control than using the icons
on the other toolbars. However, the other toolbars may be more convenient.
Menu bar.
The Standard toolbar: This toolbar contains icons from common commands such as
Save, Print, Tables, and Spell Check. These icons are convenient but will not bring up the
dialogue boxes that allow you to change the settings of these actions. You should use
whichever method works the best for you.
Standard toolbar.
The Formatting toolbar: This toolbar contains icons for common formatting actions,
such as Font Style, Font Size, Bold, Italic, Underline, Alignment, Numbered List,
Bulleted List, Indentation, Spacing, and Font Color. These icons are convenient but will
not bring up dialogue boxes that allow you to change the settings of these actions. You
should use whichever method works the best for you.
Formatting toolbar.
FORMATTING
Page 12 of 58
Margins. A menu will appear where you can type the desired margin size
Page 13 of 58
From the same menu (Figure 1), select Layout to customize the layout of your document.
Click on Page Setup, and then select the orientation of your document. Click Portrait if you
want your document to be 8.5 x 11 inches (most common). Click Landscape if you want your
document to be 11 x 8.5 inches. Landscape simply flips the page 90 degrees.
FORMATTING PARAGRAPHS
To format your paragraph, first highlight the paragraph you wish to format. To highlight more
than one paragraph, click at the beginning of the paragraph and drag the mouse over the text.
To apply changes to the entire document, go to Edit > Select All. To specify Alignment, Line
Spacing, Indentation, and Page Break click Format > Paragraph. This will open up the
Paragraph menu (Figure 2). The Alignment option allows you to choose how you want your
paragraph to look (i.e. justified, right, center, or left). The Line Spacing option allows you to
set the desired spacing, such as single or double. The Indentation option allows you to
tab/push the line(s) in your paragraph either left or right. The Page Break option is found in
Paragraph menu, but you must first select the Line and Page Breaks tab. Page break allows
you to split a paragraph or a page up into sections. You can also bring up this menu by right
clicking (or by hitting CONTROL + click on a one button mouse) within the document and
selecting Paragraph.
Page 14 of 58
FORMATTING TEXT
Before you type, you should select your font style, size, color and attributes (such as bold, italic
and underline) by using the Formatting toolbar or by going to Format > Font. This will open
the Font menu (Figure 3). However, if you wish to change text that has already been typed,
click and drag over the text to be changed to highlight it (or go to Edit > Select All to select
the entire document) and change it as before.
Page 15 of 58
EDITING
Cut and Paste
In Microsoft Word, you can cut (delete) text from one area of a document and save that text so
it can be pasted elsewhere in the document. When you cut text, it is stored on the Clipboard.
You can also copy text. When you copy text, it is also stored on the Clipboard. Information
stored on the Clipboard stays there until new information is either cut or copied. Each time you
execute Cut or Copy, you replace the old information on the Clipboard with whatever you just
cut or copied. You can paste Clipboard information as often as you like.
Page 16 of 58
Font Size
In Microsoft Word, you can change the size of your font (text). The following exercise
illustrates changing the font size.
Page 17 of 58
13. Choose Format > Font from the menu.
14. Choose the Font tab.
15. Type 24 in the Size field, or click 24 in the box below the Size field.
16. Click OK.
17. Your text should now look similar to the following:
"I am the smallest. I am a little bigger. I am the biggest."
Common Shortcuts
These are some common shortcuts that you can use on your keyboard in almost any
Microsoft Office program:
Copy: CTRL + C
Align Left: CTRL + L
Bold: CTRL + B
Spell Check: F7
Select All: CTRL + A
Cut: CTRL + X
Align Right: CTRL + R
Italic: CTRL + I
Thesaurus: SHIFT + F7
Undo: CTRL + Z
Paste: CTRL + V
Align Center: CTRL + E
Underline: CTRL + U
Find: CTRL + F
Save: CTRL + S
Help: SHIFT + F1
Department of Applied Science
Page 18 of 58
Redo: CTRL + Y
Inserting Symbols:
To insert a symbol that isnt on the keyboard (for example, , , 8, ., , etc.), click on the Insert
tab, and then click on Symbol. You can choose which symbol you would like to use, then
click on the Insert button when that symbol is highlighted. Click on the Close button to return
to your document.
Page 19 of 58
Spell Check
Word checks your spelling and grammar as you type. Spelling errors display with a red wavy
line under the word. Grammar errors display with a green wavy line under the error. If you
want to spell check your entire document, press F7 and click the spelling icon
, or choose
Tools > Spelling and Grammar from the menu. If you want to spell check part of your
document, highlight the area you want to spell check. Then press F7 and click the spelling icon
, or choose Tools > Spelling and Grammar from the menu.
Headers and Footers can be used to give a uniform look to the pages of your document. To
create one, go to View > Header and Footer. Use the Header and Footer toolbar to insert
and format words and objects in the header. To move between the header and footer, use the
Switch between Header and Footer button. Click Close to exit the header or footer.
Page 20 of 58
Mail merge enables you to create form letters, mailing labels, envelopes, or catalogs. There are
two files needed for a mail merge. The data source contains the data that varies in the merged
documents for example, the name and address of each recipient of a form letter. The data
source can be an existing spreadsheet, database, or text file, or a Word table that you create.
The main document contains the generic information that you want to repeat in each form
letter, mailing label, envelope, or catalog.
In the main document, merge fields (name, address, city, state, zip) are the
placeholders that tell Microsoft Word where to insert data from the data source. Merge fields
are identified by the guillemots ( ) around each field. When you execute the merge
command, Word automatically generates letters by replacing the merge fields in the main
document with the appropriate data from the source document. Each row (or record) in the data
source produces an individual form letter, mailing label, envelope, or catalog item. The idea of
a mail merge is to save you time and keystrokes; therefore, type as much information in the
main document as possible. For instance, if one of your merge fields will be a price (i.e.
$14.00), type the dollar sign in the main document so you wont have to type it for every price
in the source document.
Page 21 of 58
Page 22 of 58
Page 23 of 58
Conclusion: Students are made familiar with the basics of MS Word and how to use them
on all the commands in this part of application software.
Page 24 of 58
Experiment 3
Title:
Objective: To understand the Excel in depth like creating, editing, formatting and printing
the spreadsheets , formating cells, applying formulas cells.
Introduction to MS-Excel
Start Excel 2007 from the Start Menu
Click on the Start button, point to All Programs then Microsoft Office and click on
Microsoft Office Excel 2007.
Page 25 of 58
The first screen that you will see a new blank worksheet that contains grid of cells. This grid
is the most important part of the Excel window. It's where you'll perform all your work, such
as entering data, writing formulas, and reviewing the results.
Page 26 of 58
A worksheet is the grid of cells where you can type the data. The grid divides your worksheet
into rows and columns.
Columns are identified with letters (A, B, C ), while rows are identified with numbers (1,
2, 3 ).
A cell is identified by column and row. For example, B8 is the address of a cell in column B
(the second column), and row 8 (the eighth row).
A worksheet in Excel 2007 consists of 16,384 columns and over 1 million rows. The
worksheets in turn are grouped together into a workbook.
By default each workbook in Excel 2007 contains 3 blank worksheets, which are identified
by tabs displaying along the bottom of your screen. By default the first worksheet is called
Sheet1, the next is Sheet2 and so on as shown here.
Page 27 of 58
Office button: When clicked, this button opens the Office menu, from which you can open,
save, print, and exit as well as the Excel Options button that enables you to change Excel's
default settings.
Quick Access Toolbar: A small toolbar next to the Office button contains shortcuts for some
of the most common commands such as Save, Undo, and Redo buttons. You also can
customize quick access toolbar.
Ribbon: A combination of old versions menu bar and toolbar, arranged into a series of tabs
ranging from Home through View. Each tab contains buttons, lists, and commands.
Name box: Displays the address of the current active cell where you work in the worksheet.
Formula bar: Displays the address of the active cell on the left edge, and it also shows you
the current cell's contents.
Worksheet area: This area contains all the cells of the current worksheet identified by
column headings, using letters along the top, and row headings, using numbers along the left
edge with tabs for selecting new worksheets.
Sheet tabs: Excel 2007 contains 3 blank worksheet tabs by default. Click on the intended tab
will go to the particular worksheet.
Status bar: Reports information about the worksheet and provides shortcuts for changing the
view and the zoom.
Zoom control: Use to zoom the Excel screen in or out by dragging the slider.
Page 28 of 58
Office Button: On the far left side of the Ribbon, the Office Button lets you perform tasks
that are common across many Office applications.
Quick Access Toolbar: Located on top of the Excel screen beside the Office Button.
Tab: Excel's main tasks are brought together and display all the commands commonly
needed. Clicking a tab name once activates the tab.
Group: A section of a tab that organizes related command buttons into subtasks. For
example, the Home tab has the following groups: Clipboard, Font, Alignment, Number,
Styles, Cells, and Editing.
Dialog box launcher: A small icon in the bottom-right corner of a group, from which you
can open a dialog box related to that group.
Home: Use this tab when creating, formatting, and editing a spreadsheet.
Insert: Use this tab when adding particular elements (including graphics, PivotTables, charts,
hyperlinks, and headers and footers) to a spreadsheet.
Page Layout: Use this tab when preparing a spreadsheet for printing or reordering graphics
on the sheet.
Department of Applied Science
Page 29 of 58
Formulas: Use this tab when adding formulas and functions to a spreadsheet or checking a
worksheet for formula errors.
Data: Use this tab when importing, querying, outlining, and subtotaling the data placed into
a worksheet's data list.
Review: Use this tab when proofing, protecting, and marking up a spreadsheet for review by
others.
View: Use this tab when changing the display of the Worksheet area and the data it contains.
Press the Enter key. Text entries are left aligned by default.
If you want to enter a negative number, type a minus sign in front of it or enclose it in
parentheses (bracket), e.g. -15 or (15).
Select the cell in which you want to enter the date or time.
Type in the date or time. Separate the date with either hyphens (-) or slashes (/).
Press Enter.
Enter key: Pressing the key will enters the data and moves the active cell highlight down
to the next cell in the current column.
Tab key: Pressing the key will enters the data and moves the active cell highlight to the next
cell in the current row.
Arrow keys: Pressing the key will enters the data and moves the active cell highlight to the
next cell in the direction of the specific arrow key pressed.
Department of Applied Science
Page 30 of 58
Esc key: Pressing the key will cancels the current data entry.
Save A Sheet:
To save a workbook (first time)
From Office Button, click Save OR .Click the Save button on the Quick Access Toolbar.
From the Save As dialog box displayed, ensure that you browse to the folder/disk drive that
you would like to save the file.
Enter the file name in the File name: text box. The file name can be up to 255 characters in
length.
To close a file:
You will be asked if you wish to save any changes you have made to the file.
Department of Applied Science
Page 31 of 58
Save As - this choice allows you to save your spreadsheet file with a new name and choose
the location to save the file.
Save - this option updates the spreadsheet file with your most recent changes. If you use Save
on a new file that hasn't been saved before, it has the same effect as Save As.
Conclusion: Students are made aware of the working of MS Excel and all the types of data
processing commands
Page 32 of 58
Experiment 4
Title: Practice with MS Power Point, Opening and closing slides, Preparation of slides,
familiarization with various tools- applying design, themes, animation on slides.
Objective: To understand the PowerPoint in depth like creating, editing and formatting
slides, also applying design, themes, animation on slides.
Theory:
Introduction to MS-PowerPoint
To start PowerPoint 2007 from the Start Menu
Click on the Start button, point to All Programs then Microsoft Office and click on
Microsoft Office PowerPoint 2007.
The first screen that you will see a new blank presentation begins automatically with one
slide.
From this first slide, you can see the Microsoft PowerPoint 2007 environment consists of the
following elements:
When you click the Office Button, commands related to managing PowerPoint and
PowerPoint presentations are gathered together on this menu.
The Title bar displays the name of the active presentation. At the right end of the title bar
are the three familiar buttons - Minimize, Restore and Close buttons.
Below the title bar is the Ribbon, which makes all the capabilities of PowerPoint available
in a single area so that you can work efficiently with the program. You can find more
descriptions about the PowerPoint 2007 ribbon.
Across the bottom of the program window, the Status bar gives you information about the
current presentation.
At the right end of the status bar is the View toolbar, which provides tools for adjusting the
view of presentation content.
Page 33 of 58
Once you want to start learning the PowerPoint 2007, it's important to know the PowerPoint
2007 Screen Elements as well as its functions.
Office button: Opens the Office menu, from which you can open, save, print, and start new
presentations.
Quick Access Toolbar: A small toolbar next to the Office button contains shortcuts for some
of the most common commands.
Title bar: Identifies the PowerPoint program running and the name of the active presentation.
Minimize button: Shrinks the application window to a bar on the taskbar; you click its button
on the taskbar to reopen it.
Maximize/Restore button: If the window is maximized (full screen), click will changes it
to windowed (not full screen) and vice versa.
Ribbon: Functions as a combination of menu bar and toolbar, offering tabbed "pages" of
buttons, lists, and commands.
Presentation window: Where active PowerPoint slide(s) appear where you work on the
slide.
Status bar: Reports information about the presentation and provides shortcuts for changing
the view and the zoom.
Page 34 of 58
Slide is the foundation of a presentation. To create a presentation, you need to add new slide
to your presentation.
A slide layout contains placeholders, such as text, chart, table, or Smart Art graphic, where you
can enter text or insert elements.
When you create a new slide, you can apply a standard layout or a custom layout of your own
design. You can also apply a layout to an existing slide at any time.
From the New Presentation dialog box displayed, select Blank Presentation.
Click on "Click to add title" section of the slide and enter the slide title.
Click on "Click to add subtitle" section of the slide and enter the desired text.
On the Home tab, in the Slides group, click the lower portion of the New Slide button. This
will displayed several layouts:
Click on the intended layout will insert the slide to your presentation.
Page 35 of 58
There are several ways to copy slides from other presentations. These included:
Open two PowerPoint windows side-by-side and drag-and-drop slides between them.
Open two PowerPoint presentations, copy slides from one of them to the Clipboard (Ctrl+C),
and then paste them into the other presentation (Ctrl+V).
From Office button, click Save OR Click the Save button on the Quick Access Toolbar.
From the Save As dialog box displayed, ensure that you browse to the folder/disk drive that
you would like to save the file.
Enter the file name in the File name: text box. The file name can be up to 255 characters in
length.
Page 36 of 58
Experiment 5
Title: Write a program to print a message on screen using escape sequence.
Objective: To understand basics of C programming and basic input/output functions such
as printf() and scanf().
Conclusion: Students are taught to implement the basics of C programming and make use of
input output functions.
Page 37 of 58
Experiment 6
Title: Programs based on conditional statements.
Objective: To study various conditional control statements and implement them in different
programs.
#include<stdio.h>
#include<conio.h>
void main()
{
int number;
clrscr();
printf("Enter any number\n");
scanf("\n%d",&number);
if(number%2==0)
printf("\n%d is Even Number");
else
printf("\n%d is Odd Number");
getch();
}
OUTPUT:
Page 38 of 58
6.2 Programs to find the greatest among 3 numbers using if else statement.
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,big;
clrscr();
printf("Enter First Number\n");
scanf("%d",&a);
printf("Enter Second Number\n");
scanf("%d",&b);
printf("Enter Third Number\n");
scanf("%d",&c);
if(a>=b && a>=c)
printf("%d is greatest",a);
else if(b>=a && b>=c)
printf("%d is greatest",b);
else
printf("%d is greatest",c);
getch();
}
OUTPUT:
Page 39 of 58
6.3 Program to add, subtract, multiply, divide using switch statement.
#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
int a,b,c;
clrscr();
printf("Enter the value of First Operand");
scanf("%d",&a);
printf("Enter the value of Second Operand");
scanf("%d",&b);
printf("Enter the Choice");
scanf("%c",&ch);
printf("\n entered choice is %c",ch);
switch(ch)
{
case 'A':
c=a+b;
printf("Result after Addition of %d and %d numbers is:%d",a,b,c);
break;
default:
printf("wrong");
getch();
}
}
OUTPUT:
Conclusion: Students are made aware to implement decision logic using C programming
conditional statements in different programs.
Page 40 of 58
Experiment 7
Title: Programs based on looping statements.
Objective: To understand various looping statements and implement them in a number of
programs.
Page 41 of 58
{
printf(" ");
}
for(k=1;k<=n1;k++)
{
printf("*");
}
}
getch();
}
OUTPUT:
7.2 Program to print the table of a given number using while/ do while loop.
a)
#include<iostream.h>
#include<conio.h>
void main()
{
int number, counter=1,ans;
clrscr();
printf("Enter a number whose Table is to be printed");
scanf("%d",&number);
while(counter<=10)
{
ans=number*counter;
Department of Applied Science
Page 42 of 58
printf("%d * %d = %d",number,counter,ans) ;
counter++;
}
getch();
}
b) Using Do While Loop
#include<stdio.h>
#include<conio.h>
void main()
{
int number,counter=1,ans;
clrscr();
printf("Enter a number whose Table is to be printed");
scanf("%d",&number);
do
{
ans=number*counter;
printf("\n
%d * %d = %d",number,counter,ans) ;
counter++;
} while(counter<=10);
getch();
}
OUTPUT:
Page 43 of 58
7.3 Program to print the factorial of a number.
#include<stdio.h>
#include<conio.h>
void main()
{
int number, i;
long fact=1;
clrscr();
printf("Enter the Number whose Factorial is to be find");
scanf("%d",&number);
if(number==0)
{
fact=0;
}
else
for(i=1;i<=number;i++)
{
fact=fact*i;
}
printf("The Factorial of a Number %d is %ld ",number,fact);
getch();
}
OUTPUT:
Conclusion: Students are made aware to implement iterative logic using C programming
looping statements in a number of programs.
Page 44 of 58
Experiment 8
Title: Programs based on functions.
Objective: To understand the user defined functions and create user defined functions for
different programs.
Call by Value
#include<stdio.h>
#include<conio.h>
void swapv(int,int);
void main()
{
int a,b;
clrscr();
printf("Enter The Values of A and B");
scanf("%d %d",&a,&b);
printf("THE VALUES BEFORE SWAPPING IS ");
printf("\n A=%d B=%d",a,b);
swapv(a,b);
getch();
}
void swapv(int x,int y)
{
int temp;
temp=x;
x=y;
y=temp;
printf("\n THE VALUES AFTER SWAAPING IS ");
printf("\n A=%d B=%d",x,y);
}
OUTPUT:
Page 45 of 58
b)
Call by Reference
#include<stdio.h>
#include<conio.h>
void swapr(int*,int*);
void main()
{
int a,b;
clrscr();
printf("Enter The Values of A and B");
scanf("%d %d",&a,&b);
printf("THE VALUES BEFORE SWAPPING IS ");
printf("\n A=%d B=%d",a,b);
swapr(&a,&b);
printf("\n THE VALUES AFTER SWAPPING IS ");
printf("\n A=%d B=%d",a,b);
getch();
}
void swapr(int *x,int *y)
{
int temp;
temp=*x;
*x=*y;
*y=temp;
}
OUTPUT:
Page 46 of 58
8.2 Program to print the sum of first n natural numbers by using recursion.
#include<stdio.h>
#include<conio.h>
int add(int n);
void main()
{
int n;
printf("enter a positive no");
scanf("%d",&n);
printf("sum=%d",add(n));
getch();
}
int add(int n)
{
if(n!=0)
return n+add(n-1);
}
Conclusion: Students are made aware of the functions and call functions using call by value
and call by reference concepts.
Page 47 of 58
Experiment 9
Title: Programs based on Arrays.
Objective: To understand the derived data types such as arrays and implement one
dimensional and multi dimensional arrays in different programs.
Page 48 of 58
Page 49 of 58
{
scanf("%d",&b[i][j]);
}
}
printf("\nFirst Matrix is");
for(i=0;i<r1;i++)
{
printf("\n");
for(j=0;j<c1;j++)
{
printf("%d\t",a[i][j]);
}
}
printf("\nSecond Matrix is");
for(i=0;i<r2;i++)
{
printf("\n");
for(j=0;j<c2;j++)
{
printf("%d\t",b[i][j]);
}
}
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
{
c[i][j]=0;
for(k=0;k<c1;k++)
{
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
}
}
printf("\nResult of Matrix Multiplication is");
for(i=0;i<r2;i++)
{
printf("\n");
for(j=0;j<c2;j++)
{
printf("%d\t",c[i][j]);
}
Department of Applied Science
Page 50 of 58
}
}
else
{
printf("Matrix Multiplication is Not Possible");
}
getch();
}
OUTPUT:
Conclusion: Students are made aware about arrays and perform various operations on
arrays.
Page 51 of 58
Experiment 10
Title: Programs based on strings.
Objective: To understand the use and implementation of strings using characters arrays and
implement various built in string manipulation functions.
Page 52 of 58
10.2 Program to check whether the string is palindrome.
a) Without using string inbuilt functions
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char str1[50];
int i=0,j=0,len=0,flag=1;
clrscr();
printf("Enter the String");
scanf("%s",&str1);
printf("\n String is:%s",str1);
while(str1[i]!= '\0')
{
len=len+1;
i++;
}
for(i=0,j=(len-1);i<(len/2);i++,j--)
{
if(str1[j]!=str1[i])
{
flag=0;
break;
}
}
if(flag==1)
{
printf("\n String is Palindrome");
}
else
{
printf("\n String is not Palindrome");
}
getch();
}
b) With using string inbuilt functions.
#include<stdio.h>
#include<conio.h>
Department of Applied Science
Page 53 of 58
#include<string.h>
void main()
{
char str1[50], str2[50];
int i;
clrscr();
printf("Enter string");
scanf("%s", &str1);
strcpy(str2, str1);
strrev(str1);
i=strcmp(str1, str2);
if(i==0)
{
printf("\nInput string is palindrome");
}
else
{
printf("\nInput string is not palindrome");
}
getch();
}
OUTPUT:
Conclusion: Students are made aware of the concept of strings and use string manipulation
functions.
Page 54 of 58
Experiment 11
Title: Programs based on structures and unions.
Objective: To understand user defined data types and create user defined data types using
structures and unions.
Page 55 of 58
OUTPUT:
Page 56 of 58
Conclusion: Students are taught to create user defined data types using structures and unions
and use them in programs.
Page 57 of 58
Experiment 12
Title: Programs based on files.
Objective: To understand the concept of files and perform various file operations using C
programs.
Page 58 of 58
Conclusion: Students are taught to implement various file related concepts using various
file manipulation functions.