0% found this document useful (0 votes)
23 views58 pages

FOPLAB

The document is a laboratory manual for basic programming and computer assembly, detailing weekly programming exercises in C, hardware components of a computer, and instructions for installing Windows XP. It includes a structured program list, instructions for lab conduct, and descriptions of computer peripherals. Additionally, it provides a step-by-step guide for installing Windows XP, including BIOS settings and formatting procedures.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views58 pages

FOPLAB

The document is a laboratory manual for basic programming and computer assembly, detailing weekly programming exercises in C, hardware components of a computer, and instructions for installing Windows XP. It includes a structured program list, instructions for lab conduct, and descriptions of computer peripherals. Additionally, it provides a step-by-step guide for installing Windows XP, including BIOS settings and formatting procedures.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 58

BASIC PROGRAMMING LABORATORY MANUAL

Student Name:……………………………………………

RollNo :……………………………………………………

Branch:……………………………..Section………………

Year …………………………Semester…………………..
CONTENTS

Week Name of the program Page


no
a) Write a C program to find sum and average of three numbers.
b) Write a C program to find the sum of individual digits of a given
1 1-6
positive integer.
c) Write a C program to generate the first n terms of the Fibonacci sequence.
a) Write a C program to generate prime numbers between 1 to n.
b) Write a C program to Check whether given number is Armstrong Number or
2 7-12
Not.
c) Write a C program to evaluate algebraic expression (ax+b)/(ax-b).
a) Write a C program to check whether given number is perfect number or Not.
3 13-15
b) Write a C program to check whether given number is strong number or not.
a) Write a C program to find the roots of a quadratic equation.
4 16-21
b)Write a C program perform arithmetic operations using switch statement.
a) Write a C program to find factorial of a given integer using non-recursive
function.
5 22-25
b) Write a C program to find factorial of a given integer using recursive function.
a) Write C program to find GCD of two integers by using recursive function.
6 26-29
b) Write C program to find GCD of two integers using non-recursive function.
a) Write a C program to find both the largest and smallest number in a list of
integers.
b) Write a C Program to Sort the Array in an Ascending Order. 30-34
7
c) Write a C Program to find whether given matrix is symmetric or not.

8 Revision of Programs
a) Write a C program to perform addition of two matrices.
b)Write a C program that uses functions to perform Multiplication of Two
9 35-40
Matrices.
a) Write a C program to use function to insert a sub-string in to given main string
from a given position.
10 41-45
b) Write a C program that uses functions to delete n Characters from a
given position in a given string.
a) Write a C program using user defined functions to determine whether the
given string is palindrome or not.
11 46-49
b) Write a C program that displays the position or index in the main string
S where the sub string T begins, or - 1 if S doesn't contain T.
a) Write C program to count the number of lines, words and characters in a given
text.
12 50-53
b) Write a C program to find the length of the string using Pointer.

13 a) Write a C program to Display array elements using calloc( ) function. 54-55


b)Write a C Program to Calculate Total and Percentage marks of a student using
structure.
a)Write a C program that uses functions and structures to perform the following
operations:
i) Reading a complex number ii) Writing a complex number 56-60
14
iii) Addition of two complex numbers iv) Multiplication of two complex numbers
b) Write a C program to display the contents of a file.
15 a) Write a C program to copy the contents of one file to another. 61-67
b) Write a C program to merge two files into a third file.
c) Write a C program to reverse the first n characters in a file.
Revision of Programs
16

INSTRUCTIONS TO STUDENTS

 Before entering the lab the student should carry the following things (MANDATORY)
1. Identity card issued by the college.
2. Class notes
3. Lab observation book
4. Lab Manual
5. Lab Record
 Student must sign in and sign out in the register provided when attending the lab
session without fail.
 Come to the laboratory in time. Students, who are late more than 15 min., will not
be allowed to attend the lab.
 Students need to maintain 100% attendance in lab if not a strict action will be taken.
 All students must follow a Dress Code while in the laboratory
 Foods, drinks are NOT allowed.
 All bags must be left at the indicated place.
 Refer to the lab staff if you need any help in using the lab.
 Respect the laboratory and its other users.
 Workspace must be kept clean and tidy after experiment is completed.
 Read the Manual carefully before coming to the laboratory and be sure about what
you are supposed to do.
 Do the experiments as per the instructions given in the manual.
 Copy all the programs to observation which are taught in class before attending the
lab session.
 Students are not supposed to use floppy disks, pen drives without permission of lab-
in charge.
 Lab records need to be submitted on or before the date of submission.
AIM:To identify the peripherals of a computer, assemble and disassemble the system.

Software Requirement: No Software Required.

Hardware Requirement: Desired Configuration for the above task is


 System unit
 CPU
 Mother Board
 FDD
 CDROM Drive
 HDD
 Ethernet Card
 Monitor, Keyboard, Mouse & Speakers

BLOCK DIAGRAM OF COMPUTER

Peripherals of a computer:

1. Cabinet:
 It is used to install all hardware devices like (motherboard, SMPS, HDD, CDRom,
FDD)
 It has Start, Restart Button, Led’s, Audio and USB Connecters are available
at front side.

2. Monitor:

 Monitor of a computer is like a television screen.


 It displays text characters and graphics in colors or in shades of grey.
 The monitor is also called as screen or display or CRT (cathode ray tube).In the monitor the
screen
will be displayed in pixels format.
3. Keyboard
 Keyboard is like a typewriter, which contains keys to feed the data or information in to the computer
 Keyboards are available in two modules. These are
 Standard key board with 83-88 keys
 Enhanced key board with 104 keys or above

4. Mouse:

 Every mouse has one primary button (left button) and one secondary button (right button).
 The primary button is used to carry out most tasks, whereas secondary button is used in
special cases you can select commands and options.

5. Printer:

 A device that prints images (numbers, alphabets, graphs, etc…) on paper is known as Printer.
 We have different types of printers to take printouts. These are as follows:

i. Dot matrix printer ii. Inkjet printer

6. Speakers:

 Speakers make your system much more delightful to use entertain you while you
are working on computer

7. Scanner: Scanner used to scan images and text.

8. System board/Motherboard

 This is the major part of the PC hardware


 It manages all transactions of data between CPU peripherals Which holds the Processor,
Random Access Memory and other parts, & has slots for expansion cards
 It is rectangle shape
9. Socket478:
It use 478–PIN MICRO PGA package. It is used installing CPU

10. CPU

 The central processing unit contains the heart of any computer,


the processor. The processor is fitted on to a Mother Board. The Mother Board contains
various components, which support the functioning of a PC.
 It is brain of the computer
 It is square shape

11. RamSlots:

 Ram slots are used to install the rams


 It is large rectangle shape and each ending has small clips.
 There two type ram slots
 SD Ram ----------Two Gaps (synchronous DRAM) is a generic name for various kinds of
dynamic random access memory (DRAM) that are synchronized with the clock speed that
the microprocessor is optimized for. This tends to increase the number of instructions that
the processor can perform in a given time.
 DDR Ram-------One Gap (Double Data Rate Synchronous DRAM: A clock is used to read
data from a DRAM. DDR memory reads data on both the rising and falling edge of the
clock, achieving a faster data rate.)
12. North Bridge:

 It is also called as controller


 It is near by socket 478
 It placed middle of them other board
 It converts electronic signals to binary values and binary values to
electronic signals

13. South Bridge:

 It is controls major components mother board and it back bone of the input& output devices
 It is communicates PCI slots, IDE-1, IDE-2, floppy connecter, BIOSchip.
 It nearby CMOS battery

14. CMOS Battery:


 Computer is using a coin shape battery
 It generates the clock signal and it manage system continues time.

15. Primary & Secondary (IDE-1&IDE-2):


 It is also called as IDE-1, IDE-2.
 It used to connecting Hard Disk Drive, CDROM, DVDROM.

16. Input & Output ports:


 IO ports are used to connecting IO device such as keyboards, mouse, monitor, printer,
scanner, speakers etc...

17. AGP Slot & AGP Card:


 AGP Slot is used install the AGP card.
 AGP back view same as VGA port (15-female pins) and used to connecting the
monitor’sc. This slot is above PCI slots and its color is Black or Brown
18. CI Slots & PCI (Expansion) Cards:
 PCI slots are used to install the PCI cards such as

i. LAN(Ethernet)Card---Back view Ethernet port


ii. Sound Card-Back view Audio pin connectors)
iii. TV Tuner (Internal) Card –Dish Pin connecter
iv. PCI Slots are white or yellow color
v. PCI Card has Single gap only

19. BIOS Chip:


 BIOS control show the operating system and hardware
 BIOS identification is BIOS name that is available on chip or motherboard

20. ATX Power connecter:


 ATX power connecter is used to connect ATX power plug (This is
from SMPS)
 It is white color and it has ATX Name is available on Mother Board
 ATX Power connecter has 20/24 pins available.
 Typical ATX 1.3 power supply. From left to right, the connectors are 20-pin motherboard,
4-pin "P4connector", fan RPM monitor (note the lack of a power wire), SATA power
connector (black), "Molex connector" and floppy connector.

21. Floppy connecter:


 Floppy connecter is used to connect Floppy Disk Drive.
 This is beside of ATX power connecter and Name FDD is available on the motherboard.
22. Bus Cables or Data cables:
 A bus is collection of wires through which data is transmitted from one devices to another
devices. They are two types:
 IDE cable: it used to connect HDD,CDROM,DVDROM
 FDD cable: it used to connect FDD (braking or manufacture defecting)

23. Hard Disk Drive:


 The hard disk drive is the main, and usually largest, data storage device in a computer
 The operating system, software titles and most other files are stored in the hard disk drive
 Identifications is the panel name is Hard Disk drive

24. CD ROM Drive & CD-Writer:


 CD-Rom (Compact Disk Read only Memory) Drive is a device that reads the information from
Compact Disks (CD).
 CD-Writer is used to write the data into Compact Disks.
 Identification is the panel name is CD Writer
25. Floppy Disk Drive:

 The floppy disk drive is used to read the information stored in floppy disks.
 Floppy disks also called as a diskette.
 Identification is smaller than CD Writer.

26. SMPS:

 SMPS is used to supply the power to Mother Board HDD, CDROM, FDD.
 In SMPS holds a transformer, voltage control and fan
 Identification is the rectangular box shape and panel name is switching mode power
supply.
AIM: To install Windows XP

PROCEDURE:
1. Keep on press the delete button and go to advanced BIOS feature [ BIOS- Basic Input
Output System ]
2. And go to boot sequence. Select first boot drivers. CD ROM and press F10 to save the
bios feature. Yes and then enter. Press any key to boot from CD. Press enter to setup
windows XP.
F8=To agreethe license.
3. Press ESC to don‘t repair the windows XP setup.
4. Press‗p‘ to deletet he previous partitions. Then press enter.
5. Press‗L‘ to delete the partition.
6. Press‗C‘ to create the partition in the UN partition space.
7. Press enter to setup windows XP on the selected items.
BASIC FILE SYSTEMS:
FAT: File Allocation Table.
NTFS: New Technology File System. Format the create using NTFS
partition.
BASIC STEPS ININSTALLATION:-

1. Collecting information.
2. Dynamic update
3. Preparing installation
4. Installing windows.
5. Tracking installation

Screenshots of windows XP Installation


1. Insert the Windows XP CD into your computer and restart your computer. If
prompted to start from the CD, press SPACE BAR. If you miss the prompt (itonly appears for a
few seconds), restart your computer to try again.
2. Windows XP Setup begins. During this portion of setup, your mouse will not work,
so you must use the keyboard. On the Welcome to Setup page, press ENTER.

3. On the Windows XP Licensing Agreement page, read the licensing agreement.


Press the PAGEDOWN key to scroll to the bottom of the agreement. Then press F8.
4. This page enables you to select the hard disk drive on which Windows XP will be
installed. Once you complete this step, all data on your hard disk drive will be removed and
cannot be recovered. It is extremely important that you have a recent backup copy of your files
before continuing. When you have a backup copy, press D, and then press L when prompted.
This deletes your existing data. Press ENTER to select Un partitioned space, which appears by
default.

5. Press ENTER again to select Format the partition using the NTFS file system,
which appears by default.
6. Windows XP erases your hard disk drive using a process called formatting and then
copies the setup files. You can leave your computer and return in 20 to 30 minutes.

7. Windows XP restarts and then continues with the installation process. From this point
forward, you can use your mouse. Eventually, the Regional and Language Options page
appears. Click next to accept the default settings. If you are multilingual or prefer a language
other than English, you can change language settings after setup is complete
8. On the Personalize Your Software page, type your name and your organization name.
Some programs use this information to automatically fill in your name when required. Then,
click Next.

9. On the Your Product Key page, type your product key as it appears on your Windows
XP CD case. The product key is unique for every Windows XP installation.
Then, click Next.

10. On the Computer Name and Administrator Password page, in the Computer name
box, type a name that uniquely identifies your computer in your house, such as FAMILYROOM
or TOMS. You cannot use spaces or punctuation. If you connect your computer to a network,
you will use this computer name to find shared files and printers. Type a strong password that
you can remember in the Administrator password box, and then retype it in the Confirm
password box. Write the password down and store it in a secure place. Click Next.

11. On the Date and Time Settings page, set your computer‘s clock. Then, click the
Time Zone down arrow, and select your time zone. Click Next.

12. Windows XP will spend about a minute configuring your computer. On the
Networking Settings page ,click Next.

13. On the Work group or Computer Domain page, click Next.


14. Windows XP will spend 20 or 30 minutes configuring your computer and will Automatically
restart when finished. When the Display Settings dialog appears, click OK.

15. When the Monitor Settings dialog box appears, click OK.

16. The final stage of setup begins. On the Welcome to Microsoft Windows page, click next.

17. On the Help protect your PC page, click Help protect my PC by turning on
Automatic Updates now. Then, click
18. Windows XP will then check if you are connected to the Internet: If you are
connected to the Internet, select the choice that describes your network connection on the Will
this computer connect to the Internet directly, or through a network? Page. If you‘re not
sure, accept the default selection, and click Next

19. If you use dial-up Internet access, or if Windows XP cannot connect to the
Internet, you can connect to the Internet after setup is complete. On the How will this computer
connect to the Internet? Page, click Skip.
20. Windows XP Setup displays the Ready to activate Windows? Page.
If you are connected to the Internet, click Yes, and then click Next. If you
are not yet connected to the Internet, click No, click Next, and then skip
to step24. After setup is complete, Windows XP will automatically
remind you to activate and register your copy of Windows XP

21. On the Ready to register with Microsoft? Page, click Yes, and then click Next.

22. On the collecting registration information page, complete the form. Then, click Next.
23. On the Who will use this computer? page, type the name of each
person who will use the computer. You can use first names only,
nicknames, or full names. Then click Next. To add users after setup is
complete or to specify a password to keep your account private, read
Create and customize user accounts.

24. On the Thank you! Page, click Finish.


Congratulations! Windows XP setup is complete.

TEST DATA: No Test data for this Experiment

ERROR: No Errors for this Experiment

RESULT: Installation of Windows XP is completed.

EXNO : 2. Preparing a Modern Resume in MS Word


AIM

To create a professional resume using Microsoft Word that effectively highlights your
qualifications and experiences.

Procedure

Open Microsoft Word


Step 1: Go to File > New documents.
Step 2: select Blank Document.
Step 3. Set margins to 1 inch (go to Layout > Margins > Normal).
Step 4. Choose a professional font (e.g., Arial, Calibri, or Times New Roman) with a size of 10-
12 points.
5. Title: Align left your name at the top in a larger font size (16 points). You can make it bold.
6. Add Contact Information
7. Below your name, add your contact details:
Phone number
Email address
LinkedIn profile (if applicable)
Select The information text and Align this information to the left using CTRL + L.
8. Insert a picture of you in a circle shape dialog box and Align it right using CTRL + R.
9. Draw a horizontal line for Creating Resume Sections
10. Insert a heading Objective with bold style font size 13 and font style time new roman
11. Write a brief statement about your career goals and what you can offer.
12. Insert a heading “Education” with bold style font size 13 and font style time new roman and
list your degrees in reverse chronological order.
13. Include the degree, institution name, location, and graduation date.
14. Insert a heading “Work Experience” with bold style font size 13 and font style time new
roma and list your jobs in reverse chronological order.
For each position, include:
Job title
Company name
Location
Dates of employment
15. Use bullet points to describe your responsibilities and achievements.
16. Insert a heading “Skills” with bold style font size 13 and font style time new roman and list
relevant skills that align with the job description.
Include any certifications, volunteer work, or professional affiliations.
17. Insert a table with 3 columns and 5 rows for entering personal details such as father name,
mother name, nationality, languages known, date of birth.
18. Insert border for whole document using Border keyword.
19. Save your document by going to File > Save As.
20.Choose a location on your computer and name the file appropriately (e.g.,
"FirstName_LastName_Resume").
21. Save the document in PDF format for submission by selecting File > Save As, then choose
PDF from the dropdown menu.
Result:
Thus, the professional resume is successful developed using MS Office Word.

EX NO; 4 STUDENT RESULT ANALYSIS USING EXCEL


AIM: To prepare students mark list is Ms-excel by using Formulas.

PROCEDURE:
STEP : 1. First go to file menu and choose new sub menu and select work sheet option and click
ok.
STEP : 2. Enter the fields Reg No, students name, subject-Tamil, English, Maths, Science,
Social, Total, Average, Result and grade.
STEP : 3. Enter the Register number, names, and marks and grade.
STEP : 4. To find the total, Enter the Formula = sum (ex: C3:H3) this will give the total at the
marks.
STEP : 5. Enter the formula in the formula bar finding average . =average (total/no of subjects)
STEP : 6. In the result column type the formula in the formula menu as = IF(AND
(Tamil>=40,English>=40,Maths>=40,Science>=40,Science>=40),”pass”,”fail”) the result of the
student will be displayed.
STEP : 7. In the grade column the formula in the formula bar
=IF(cellNo>=100,”Distinction”,IF(cell No>=60,”First”,IF(cell No>=50,”SE(NO)”,IF(cell
No>=40,”NIL”). This will give the grade of the student.
STEP : 8. Select the data table.
STEP : 9. choose the chart wizard from insert menu be the chart type.
STEP : 10. Give the chart like and define X-axies and Y-axies.
STEP : 11. Finally click the finish button new we get the chart for the data table selected.
STEP : 12. save the file.

RESULT: Thus student mark sheet is prepare, in Ms-excel using formulas.

EX NO: SWAPPING (WITH TEMPORARY VARIABLE)


DATE:
Aim:
To swap the values of two variables using a C program.
Algorithm:
STEP 1: Start the program
STEP 2: Get the values of x and y
STEP 3: Print the entered values of x and y
STEP 4: Swap the values of x and y by
t=x
x=y
y=t
STEP 5: print after swapping values of x and y
STEP 6: Stop the program.

Flowchart :

Start

Read a,b

Print a,b before swap

t=a
a=b
b=t

Print a,b after swap

Stop
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int x,y,t;
clrscr();
printf("enter the value of x=");
scanf("%d",&x);
printf("enter the value of y=");
scanf("%d",&y);
t=x;
x=y;
y=t;
printf("\n after swapping the value:x=%d,y=%d",x,y);
getch();
}

Output:
Enter the value of x=4
Enter the value of y=7
After swapping the value : x=7 y=4

Result:
Thus a C program to swap the values of two variables is written and executed
successfully.
EX NO: FINDING LEAP YEAR OR NOT

Aim:
To find whether the year is leap year or not using C program
Algorithm:
STEP 1: Start the program
STEP 2: Get the year to find leap year or not
STEP 3: Check for leap year through year%400==0, year%100!=0 and year%4==0
STEP 4: If true print leap year, else print not leap year
STEP 5: stop the program

Flowchart:

Sta rt

Read Year

If year %400==0 and


year%100!=0 and year
%4==0

yes No
Print Leap Year Print not leap year

Stop
Program:
#include <stdio.h>
#include<conio.h>
void main()
{
int year;
printf("Enter a year: ");
scanf("%d", &year);
if (year % 400 == 0&&year%100!=0&&year%4==0)
{
printf("%d is a leap year.", year);
}
else {
printf("%d is not a leap year.", year);
}
getch();
}
Output:
Enter a year : 2012
2012 is a leap year
Enter a year : 2021
2021 is not a leap year

Result:
Thus a C program to find the year is leap year or not is written and executed
successfully
EX NO:2C MENU DRIVEN CALCULATOR
DATE:
Aim:
To write a C program to implement a menu driven calculator
Algorithm:
STEP 1: Start the program
STEP 2: Enter the arithmetic operation has to be performed in calculator
STEP 3: Enter two numbers for performing arithmetic operation
STEP 4: If addition is chosen add the two numbers and save the result
STEP 5: If subtraction is chosen subtract the two numbers and save the result
STEP 6: If Multiplication is chosen multiply the two numbers and save the result
STEP 7: If division is chosen divide the two numbers and save the result
STEP 8: Print the result
STEP 9: Stop the program

Flow Chart:
Start

Read a , b

Read
choice

If yes c=a+b
Choice
is add
No

If c=a-b
yes
Choice
is Sub
No

If c=a X b
yes
Choice is
Multiply
No

If yes
Choice is c=a/b Print c
Divide

No
Stop
Print Enter correct
choice
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int choice; int x,y; float z;
clrscr();
printf(“1. Addition\n”);
printf(“2.Subraction\n”);
printf(“3.Multiplication\n”);
printf(“4.Division\n”);
printf(“Enter choice:”);
scanf(“%d”,&choice);
printf(“Enter the input values:”);
scanf(“%d”,&x);
scanf(“%d”,&y);
switch(choice)
{
case 1:
z=x+y;
break;
case 2:
z=x-y;
break;
case 3:
z=x*y;
break;
case 4:
z=(float)x/y;
break;}
Printf(“The result is: %f”,z);
}
getch();
}

Output:
1.Addition
2.Subraction
3.Multiplication
4.Division
Enter choice: 1
Enter input values: 5 4
The result is 9
1.Addition
2.Subraction
3.Multiplication
4.Division
Enter choice: 2
Enter input values: 5 4
The result is 1

1.Addition
2.Subraction
3.Multiplication
4.Division
Enter choice: 3
Enter input values: 5 4
The result is 20

1.Addition
2.Subraction
3.Multiplication
4.Division
Enter choice: 4
Enter input values: 5 4
The result is 1.25

Result:
Thus a C program to implement a Menu driven calculator is written, executed and output is
verified.
EX NO: SUM OF EVEN NUMBERS
DATE:

Aim:
To write a C program to find sum of even numbers
Algorithm:
STEP 1: Start the program
STEP 2: Read a positive number upto which finding sum
STEP 3: Check whether the number is even or not
STEP 4: If even add to find sum
STEP 5: Print the sum
STEP 6: Stop the program

Flowchart:

Start

Read num

If i
is eve n

yes n
yes o

i<nu Sum = sum+i


m

no i=i+1

Print sum

stop

Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int n,I,sum=0;
clrscr();
printf(“enter a positive number:\n”);
scanf(“%d”,&n);
for(i=1;i<=n;i++)
if(i%2==1)
{
continue;
}
sum+=i;
}
printf(“sum of even numbers from 1 to %d=%d”,n,sum);
getch();
}

Output:
Enter a positive number : 20
Sum of even numbers from 1 to 20 = 110

Result:
Thus a C program to find the sum of even numbers is written, executed and output is verified
EX NO: 4A PRINTING ARRAY OF ELEMENTS

DATE:

Aim :
To write a C program to perform mean of ‘n’ numbers using one dimensional
array

Algorithm :
STEP 1: Start the program
STEP 2: Enter no. of elements for which mean value has to be found
STEP 3: Enter ‘n’ values in an array to find mean
STEP 4: Printing the array elements
STEP 5: Stop the program

Flowchart:

Start

Read input n, a[i]

i=0

no
If i <n Stop

yes

Print a[i]

i = i+1

Program:
#include<stdio.h>
#include<conio.h>
void main(){
int i,a[50],n;
float avg;
clrscr();
printf(“Enter no of elements:”);
scanf(“%d”,&n);
printf(“Enter the values:”);
for(i=0;i<n;i++)
scanf(“%d”,&a[i]);
printf(“The values of array element are:”);
for(i=0;i<n;i++)
printf(“\na[%d]=%d”,i,a[i]);
getch();
}

Output:

Enter no. of elements: 5


Enter the values: 3 5 7 9 11

Result:
Thus a C program to printing array of ‘n’ numbers using a one dimensional array
is written, executed and output is verified.

EX NO:4B FINDING MATRIX MULTIPLICATION


DATE:
Aim:
To write a C program to find matrix multiplication using two dimensional arrays

Algorithm:
STEP 1: Start the program
STEP 2: Get values of two 3X3 matrices to be multiplied in two 2 dimensional
arrays
STEP 3: Apply necessary for loop to multiply rows with columns
STEP 4: Store the final values in a 3X3 matrix using 2d array
STEP 5: Print the values in matrix form
STEP 6: Stop the program

Flowchart :

start

Read 3X3 A matrix

Read 3X3 B matrix

Mul []=Multiply
rows of A matrix with column of B

Print Mul matrix

stop

Program:
#include<stdio.h>
#include<conio.h>
void main() {
int i, j, k;
int a[3][3], b[3][3], mul[3][3];
printf("Enter elements of the first matrix:\n");
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
printf("a[%d][%d] = ", i, j);
scanf("%d", &a[i][j]);
}
}
printf("Enter elements of the second matrix:\n");
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
printf("b[%d][%d] = ", i, j);
scanf("%d", &b[i][j]);
}
}
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
mul[i][j] = 0;
for (k = 0; k < 3; k++) {
mul[i][j] += a[i][k] * b[k][j];
}
}
}
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
printf("%d\t", mul[i][j]);
}
printf("\n");
}
getch();
}

Output:
5 6 4 8 7 1 6 9
Enter the elements of first
matrix : 2
Enter the elements of second 7 5 1 9 4 3 7 1
matrix : 8

39 101 36
61 149 59
41 124 38
Result:
Thus C program to find matrix multiplication using two dimensional array is written,
executed and output is verified
EX NO:5A FINDING PALINDROME OR NOT

DATE:

Aim:
To write a C program to find whether the given string is palindrome or not
Algorithm:
STEP 1: Start the program
STEP 2: Read the string to be checked palindrome or not
STEP 3: Compare the string with the reversed string
STEP 4: Print as palindrome if equal.
STEP 5: Print as not palindrome if not equal
STEP 6: Stop the program

Flowchart:

star t

Read string

If i<len(string)

yes
yes
Flag = 0 n If (string[i]! =
o string[len-1]) Flag = 1

Print not
Print palindrome
palindr ome

stop
Program:
#include <stdio.h>
#include <string.h>
void main() {
char string1[20];
int i, length;
int flag = 0;
printf("Enter a string: ");
scanf("%s", string1);
length = strlen(string1);
for (i = 0; i < length / 2; i++) {
if (string1[i] != string1[length - i - 1])
{ flag = 1;
break;
}
}
if (flag) {
printf("%s is not a palindrome\n", string1);
} else {
printf("%s is a palindrome\n", string1);
}
getch();
}
Output:
Enter a string : madam
madam is palindrome

Enter a string : science


science is not palindrome

Result:
Thus a C program to find whether a string is palindrome or not is written, executed and
output is verified.
EX NO:5B STRING MANIPULATION

DATE:

Aim:
To write a C program to implement string manipulation functions using string
library functions
Algorithm :
STEP 1: Start the program
STEP 2: Initialize the string variables to which string length, string copy, string
concatenate, string reverse and string compare are performed
STEP 3: String length is calculated using strlen() function and print the result STEP
4: String copy is performed by strcpy() function and print the result
STEP 5: String concatenate is performed by strcat() function and print the result
STEP 6: String reverse is performed by strrev() function and print the result
STEP 7: String compare is performed by strcmp() function and print the result
STEP 8: Stop the program

Flowchart:

Start

Declare s

Read s1,s2

strcat(s1,s2),strc
py(s,s1),strlen(s)
,strrev(s2),strcm p(s,s1)
Program:
#include <stdio.h>
#include <string.h>
#include<conio.h>
void main()
{char s1[] = "computer";
char s2[]=”science”; char s[20];
int len,cmp;
clrscr();
strcat(s1, s2);
printf("concatenated string is: %s ", s1);
strcpy(s, s1);
printf(“the copied string is: %s”, s);
len = strlen(s);
printf(“ the length of the string is:%d”,len);
strrev(s2);
printf(“reversed string is : %s”,s2);
cmp=strcmp(s,s1);
printf(“compared value is : %d”,cmp);
getch();
}

Output:
Concatenated string is : computerscience
Copied string is : computerscience
The length of the string is : 15
Reversed string is : ecneics
Compared value is : 0

Result:
Thus C program to implement string manipulation functions are written, executed and
output is verified
EX NO: 6B SWAPPING (CALL BY VALUE)

DATE:

Aim:
To write a C program to swap values of variables using call by value
Algorithm:
STEP 1: Start the program
STEP 2: Print the values of a and b before swapping
STEP 3: Pass the values as parameters to swap function
STEP 4: After swapping print the values of a and b
STEP 5: Stop the program
Flowchart:

star t

Read a,b

Display a,b
before swapping

swap(a,b)

Display a,b after


swapping

stop
Program:
#include <stdio.h>
#include<conio.h>
void swap(int x, int y) {
int temp;
temp = x; x = y;
y = temp;
printf("After swap: value of a: %d\n", x);
printf("After swap: value of b: %d\n", y);

}
void main() {
int a = 100;
int b = 200;
printf("Before swap: value of a: %d\n", a);
printf("Before swap: value of b: %d\n", b);
swap(a, b);
getch();
}
Output:
Before swap: value of a: 100
Before swap: value of b: 200
After swap: value of a:200
After swap: value of b:100

Result:
Thus C program to swap values using call by value is written, executed and output is
verified
EX NO: 6C SWAPPING(CALL BY REFERENCE)

DATE:

Aim:

To write a C program to swap values of variables using call by reference


Algorithm:
STEP 1: Start the program
STEP 2: Print the values of a and b before swapping
STEP 3: Pass the addresses as parameters to swap function
STEP 4: After swapping print the values of a and b
STEP 5: Stop the program

Flowchart:

star t

Read a,b

Display a,b
before swapping

swap(&a, &b)

Display a,b after


swapping

stop
Program:
#include <stdio.h>
#include<conio.h>
void swap(int *x, int *y) {
int temp;
temp = *x;
*x = *y;
*y = temp;
}
void main() {
int a = 100;
int b = 200;
printf("Before swap: value of a: %d\n", a);
printf("Before swap: value of b: %d\n", b);
swap(&a, &b);
printf("After swap: value of a: %d\n", a);
printf("After swap: value of b: %d\n", b);
getch();
}
Output:
Before swap: value of a: 100
Before swap: value of b: 200
After swap: value of a:200
After swap: value of b:100

Result:
Thus C program to swap values using call by value is written, executed and output is verified
EX NO: 7 POWER OF A NUMBER USING RECURSION
DATE:

Aim:
To write a C program to find power of a number using recursion
Algorithm:
STEP 1: Start the program
STEP 2: Read the base integer number
STEP 3: Read the power integer number
STEP 4: Power of base number is calculated using recursion
STEP 5: Print the result
STEP 6: Stop the program

Flowchart:

start

Read base num

Read power nuum

If power
!=0

Result =
power*base Print result

power=power-1 stop
Program:
#include<stdio.h>
#include<conio.h>
int power(int base,int p);
void main()
{
int base,p,result;
clrscr();
printf(“Enter the base number:”);
scanf(“%d”,&base);
printf(“Enter power number:”);
scanf(“%d”,&p);
result=power(base,p);
printf(“%d^%d=%d”,base,p,result);
getch();
}
int power(int base,int p)
{
if(p!=0)
return(base*power(base,p-1));
else
return 1;
}

Output:
Enter the base number: 2 Enter power number: 4 2^4 = 16

Result:

Thus C program to find power of a number using recursion is written, executed and
output is verified
EXNO: 8D POINTER TO POINTER

DATE:

Aim:
To write a C program print values of pointer to pointer

Algorithm:
STEP 1: Start the program
STEP 2: Initialize a value to a variable
STEP 3: Store the variable to pointer variable
STEP 4: Now store the pointer variable to pointer to pointer variable
STEP 5: Print the values
STEP 6: Stop the program

Flowchart:

start

Read val

ptr=&val
ptr_to_ptr=&pt r

Print *ptr Print *ptr_to_ptr

stop
Program:
#include <stdio.h>
#include<conio.h>

void main() {
int val;
int *ptr;
int **ptr_to_ptr;
val = 10;
*ptr = &val;
**ptr_to_ptr = &ptr;
printf("Value of val: %d\n", val);
printf("Value using ptr: %d\n", *ptr);
printf("Value using ptr_to_ptr: %d\n", **ptr_to_ptr);
getch();
}

Output:
Value of val: 10 Value using ptr: 10
Value using ptr_to_ptr : 10

Result:
Thus C program to print values using pointer to pointers is written, executed and output is
verified
EX NO: 9 STUDENT RECORD USING STRUCTURE

DATE:

Aim:
To write a C program to write student record using structure

Algorithm:
STEP 1: Start the program
STEP 2: Define a structure for creating student record
STEP 3: Initialize a structure variable to access structure member variables
STEP 4: Obtain values for member variables
STEP 5: print the student record
STEP 6: stop the program

Flowchart:

start
struct Student {
char* name;
int roll_number;
int age;
double total_marks;
};

Struct student s[5]

i<n

Print s[i].name,s[i].rollnumber,
s[i].age,s[i].total_marks sto p

i=i+1
Program:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct Student {
char* name;
int roll_number; int age;
double total_marks;
};

void main()
{
int i = 0;
struct Student student[5];

student[0].roll_number = 1; student[0].name = "Anand"; student[0].age = 12;


student[0].total_marks = 78.50;

student[1].roll_number = 2; student[1].name = "Babu"; student[1].age = 10;


student[1].total_marks = 56.84;

student[2].roll_number = 3; student[2].name = "Daisy"; student[2].age = 11;


student[2].total_marks = 87.94;

student[3].roll_number = 4; student[3].name = "Ganga"; student[3].age = 12;


student[3].total_marks = 89.78;

student[4].roll_number = 5; student[4].name = "Ishwarya"; student[4].age = 13;


student[4].total_marks = 78.55;

printf("Student Records:\n\n"); for (i = 0; i < n; i++)


{
printf("\tName = %s\n", student[i].name);
printf("\tRoll Number = %d\n", student[i].roll_number); printf("\tAge = %d\n",
student[i].age);
printf("\tTotal Marks = %0.2f\n\n", student[i].total_marks);
}

getch();
}
Output:
Student Records:
Name = Anand Roll Number = 1 Age = 12
Total Marks = 78.50

Name = Babu Roll Number = 2 Age = 10


Total Marks = 56.84

Name = Daisy Roll Number = 3 Age = 11


Total Marks = 87.94

Name = Ganga Roll Number = 4 Age = 12


Total Marks = 89.78

Name = Ishwarya Roll Number = 5 Age = 13


Total Marks = 78.55

Result:
Thus C program to get student records and print the record is written, executed and
output is verified.
EX NO : 10 DEFINING AN UNION

DATE :

Aim :
To write a C program to declare and initialise a Union
Algorithm:
STEP 1: Start the program
STEP 2: Define a union MyUnion
STEP 3: Define member variables and union variable
STEP 4: Initialize a value
STEP 5: Print the value
STEP 6: Stop the program

Flowchart:

Start

union MyUnion {
int intValue;
char charValue;
float floatValue;
}; myVar;

myVar.intValue =42;

Print myVar.intValue

stop
Program:

#include <stdio.h>

#include<conio.h>
union MyUnion {
int intValue;
char charValue;
float floatValue;
};
void main() {
union MyUnion myVar;

myVar.intValue = 42;
printf("Value stored in intValue: %d\n", myVar.intValue);
getch();
}

Output:
Value stored in intValue : 42

Result :
Thus C program to declare and initialize Union is written, executed and output is
verified.
EX NO: READ AND PRINT CONTENTS OF FILES
DATE:

Aim:
To write a C program to read and print contents of a file
Algorithm:
STEP 1: Start the program
STEP 2: create a file pointer to open a file
STEP 3: open a file for read access
STEP 4: read the contents of the file
STEP 5: print the contents of file
STEP 6: close the file
STEP 7: stop the program

Flowchart:

Star t

Create file pointer

Open ‘jtp.txt’ for ‘read’

Print the file contents

Close the file

stop
Program:
#include<stdio.h>

#include<conio.h>

void main()
{
FILE *fp;
fp = fopen("Jtp.txt","r");

if(!fp)
{
printf("Error in opening file\n");

return 0;
}
//The file pointer always starts at the beginning of the file.

printf("Position of the pointer : %ld\n",ftell(fp));


char ch;
while(fread(&ch,sizeof(ch),1,fp)==1)
{
//Here, we go through the entire file and print everything we find till we get to the finish.
printf("%c",ch);
}
printf("Position of the pointer : %ld\n",ftell(fp));
//It will return to its previous location below using the rewind() function.

rewind(fp);
printf("Position of the pointer : %ld\n",ftell(fp));
fclose(fp);
getch();
}
Output:

Result:

Thus a C program to read and print the contents of a file is written, executed and output is
verified

You might also like