FOPLAB
FOPLAB
Student Name:……………………………………………
RollNo :……………………………………………………
Branch:……………………………..Section………………
Year …………………………Semester…………………..
CONTENTS
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.
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.
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:
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:
6. Speakers:
Speakers make your system much more delightful to use entertain you while you
are working on computer
8. System board/Motherboard
10. CPU
11. RamSlots:
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
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
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.
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.
To create a professional resume using Microsoft Word that effectively highlights your
qualifications and experiences.
Procedure
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.
Flowchart :
Start
Read a,b
t=a
a=b
b=t
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
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
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
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:
Result:
Thus a C program to printing array of ‘n’ numbers using a one dimensional array
is written, executed and output is verified.
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
Mul []=Multiply
rows of A matrix with column of B
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
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)
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:
Flowchart:
star t
Read a,b
Display a,b
before swapping
swap(&a, &b)
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
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
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;
};
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];
getch();
}
Output:
Student Records:
Name = Anand Roll Number = 1 Age = 12
Total Marks = 78.50
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
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.
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