0% found this document useful (0 votes)
68 views75 pages

C Lab Manual

The document is a laboratory activity manual for PSRR College of Engineering, detailing various programming exercises in C. It includes a list of experiments covering topics such as I/O statements, decision-making constructs, leap year determination, and designing a calculator. Each exercise outlines the aim, reference materials, required apparatus, principles, steps, and example code for implementation.

Uploaded by

ustar9520
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)
68 views75 pages

C Lab Manual

The document is a laboratory activity manual for PSRR College of Engineering, detailing various programming exercises in C. It includes a list of experiments covering topics such as I/O statements, decision-making constructs, leap year determination, and designing a calculator. Each exercise outlines the aim, reference materials, required apparatus, principles, steps, and example code for implementation.

Uploaded by

ustar9520
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/ 75

LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

Table Of Contents
S.NO LIST OF EXPERIMENTS
1. Programs using I/O statements and expressions
2. Programs using decision-making constructs
3. Write a program to find whether the given year is leap year or not?(Hint:not every
centurion year is a leap.for example 1700,1800 and 1900 is not a leap year)

4. Design a calculator to perform the


operations,namely,addition,subtraction,multiplication,division and square of a
number
5. Check whether a given number is Armstrong number or not?
6. Given a set of numbers like<10,36,54,89,12,27>,find the sum of weights based on
the following conditions
5 if it is a Perfect Cube.
2 if it is a multiple of 4 and divisible by 6
3 if it is a Prime number
Sort the numbers Based on the weight in the increasing order as shown
below<10,its weight>,<36,its weight><89.its weight>.’,

7. Populate an array with height of persons and find how many persons are above the
average height

8. Populate a two dimensional array with height and weight of person and compute th
Body Mass Index of the Individuals

9 Given a String “a$bcd./fg”find its reverse without changing the position of special
characters.(Example input:a@gh%;j and output:j@hg%;a)
10 Convert the given decimal number into library,octal and hexadecimal numbers
using user defined functions
Algorithm to convert Decimal to Binary number
Divide the input decimal number by 2 and store the remainder
Store the quotient back to the input number variable.
Prepared by Reviewed By Approved by Dr.K.Sakthivel
A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

Repeat this process till quotient becomes zero


Equivalent binary number will be the remainders in above process in reverse
order.
11 From a given paragraph perform the following using built in functions:
a.Find the total number of words
b.Capitalize the first word of each sentence.
c.Replace a given word with another word.

12 SOLVE TOWERS OF HANOI USING RECURSION


This Program uses recursive function and solves the towers of Hanoi.The tower
Mathematical puzzle .it contains of three rods and a number of desks of different
sizes which can slide onto any rod .
The puzzle starts with the disks in a neet stack in assending order of size on one
rod,thesmallestat the top we have to obtain the same strack
On the third rod .here is the source cord of the c program for solving towers of
Hanoi.

13 Sort The List Of Numbers Using Pass By Reference

14 Generate salary slip of employees using structures and pointers

15 Compute internal mark of students for five different subjects using structures and
functions
16 Count the number of account holders whose balance is less than the minimum
balance using sequential access file

Prepared by Reviewed By Approved by Dr.K.Sakthivel


A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

EXERCISE-1

I/O Statements and expressions

AIM

To Write a C Program for addition and subtraction of two numbers and display the result using
I/O statements

Reference

Reema Thareja,”Programming in C”,Oxford University Press,Second Edition,2016

List of Apparatus

HARDWARE:

1. Personal Computer/user

SOFTWARE:

Turbo C compiler

PRINCIPLE

C Programming has several in built library functions to perform input and output tasks.Two
commonly used functions for I/O (Input/Output)are printf() and scanf().The Scanf() function
reads formatted input from standard input(keyboard)whereas the printf() function sends
formatted output to the standard output.An Expression is any legal combination of symbols that
represents a value.C Programming provides its own rules of Expression ,whether it is legal
expression or illegal expression.Every expression consists of at least one oprand and can have
one or more operators.Operands are values and Operators are Symbols that represent Particular
actions.

Steps:

Step1:Include necessary header files.


Prepared by Reviewed By Approved by Dr.K.Sakthivel
A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

Step2:Declare the variables a,b,c

Step3:Get a and b values from user using input statement

Step4:Perform operation addition and subtraction and store in C

Step5:Display the C value using output statement

PROGRAM

#include<stdio.h>

#include<conio.h>

void main()

int a,b,c;

printf("Enter the no=\n");

scanf("%d%d",&a,&b);

c=a+b;

printf("Addition of the numbers%d+%d=%d\n",a,b,c);

c=a+b;

printf("Subtraction of the numbers%d-%d=%d\n",a,b,c);

getch();

Prepared by Reviewed By Approved by Dr.K.Sakthivel


A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

OUTPUT

Result:

Thus a Program was implemented and the output was verified.

Prepared by Reviewed By Approved by Dr.K.Sakthivel


A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

EXERCISE-2

Decision Making Constructs

Aim:

To write a C Program for finding maximum value using decision making constructs.

Reference

Reema Thareja,”Programming in C”,Oxford University Press,Second Edition,2016

List of Apparatus

HARDWARE:

1. Personal Computer/user

SOFTWARE:

Turbo C compiler

Principle

Decision making is about deciding the order of execution of statements based on certain
conditions or repeat a group of statements until certain specified conditions are met.C Language
handles decision making by supporting the following statements,

 If statement
 Switch statement
 Conditional operator statement(?:Operator)
 Goto Statement

Steps

Step 1:Start the Program

Step2:Include the necessary header files.


Prepared by Reviewed By Approved by Dr.K.Sakthivel
A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

Step 3: Declare the variables a,b,c

Step4:Get the a,b,c values from user

Step 5:Check the outer condition as a>b using if statement

Step 5.1:If it is true then check the inner condition as a>c using if statement

Step 5.2:If the inner condition is true then print a is the greatest Else print c is the greatest

Step 7:Terminate the Program.

PROGRAM

#include<stdio.h>

void main()

int a,b,c;

printf("Enter 3 numbers");

scanf("%d%d%d",&a,&b,&c);

if(a>b)

if(a>c)

printf("a is the greatest");

else

Prepared by Reviewed By Approved by Dr.K.Sakthivel


A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

printf("c is the greatest");

}else

if(b>c)

printf("b is the greatest");

else

printf("C is the greatest");

}}}

OUTPUT

Prepared by Reviewed By Approved by Dr.K.Sakthivel


A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

Prepared by Reviewed By Approved by Dr.K.Sakthivel


A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

Result

Thus a program was implemented and the output was verified.

Prepared by Reviewed By Approved by Dr.K.Sakthivel


A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

EXERCISE-3

Leap Year or Not

Aim

To Write a C Program for finding given year is leap year or not

Reference

Reema Thareja,”Programming in C”,Oxford University Press,Second Edition,2016

List of Apparatus

HARDWARE:

1. Personal Computer/user

SOFTWARE:

Turbo C compiler

Principle

C Programming has several in built library functions to perform input and output tasks.Two
commonly used functions for I/O (Input/Output)are printf() and scanf().The Scanf() function
reads formatted input from standard input(keyboard)whereas the printf() function sends
formatted output to the standard output.An Expression is any legal combination of symbols that
represents a value.C Programming provides its own rules of Expression ,whether it is legal
expression or illegal expression.Every expression consists of at least one oprand and can have
one or more operators.Operands are values and Operators are Symbols that represent Particular
actions.

Prepared by Reviewed By Approved by Dr.K.Sakthivel


A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

Steps:

Step1:Start the Program

Step2:Include the necessary header files

Step3:Declare the variable as a year

Step4:Get the value for year from user.

Step 5:if((year%400)true print leap year

Step 6:else if ((year%100)true print not a leap year

Step7:else if ((year%4)==0)true Print leap year

Step 8:Else print not leap year

Step 9:Terminate the Program

Program

#include<stdio.h>

#include<conio.h>

void main()

int year;

printf("Enter a year");

scanf("%d",&year);

if(year%4==0)

{
Prepared by Reviewed By Approved by Dr.K.Sakthivel
A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

if(year%100==0)

if(year%100==0)

if(year%400==0)

printf(%d is a leap year",year);

else

printf("%d is not a leap year",year);

else

printf("%d is a leap year",year);

else

printf("%d is not a leap year"year);

Prepared by Reviewed By Approved by Dr.K.Sakthivel


A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

Prepared by Reviewed By Approved by Dr.K.Sakthivel


A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

Result:

Thus a program was implemented and the output was verified

Prepared by Reviewed By Approved by Dr.K.Sakthivel


A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

EXERCISE-4

Design a Calculator

Aim:

To write a C Program for design a calculator for small operation.

Reference

Reema Thareja,”Programming in C”,Oxford University Press,Second Edition,2016

List of Apparatus

HARDWARE:

1. Personal Computer/user

SOFTWARE:

Turbo C compiler

Principle

A Switch statement allows a variable to be tested for equality against a list of values.Each
value is called a case,and the variable being switched on is checked for each switch case.When
the variable being switched on is equal to a case,the statements following that case will execute
until a break statement is reached.

Steps:

Step 1:Start the Program

Step2:Include the necessary header files

Step3:Declare the necessary variables

Step4:Get the two values from user


Prepared by Reviewed By Approved by Dr.K.Sakthivel
A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

Step 5:Enter the option

Step 6:Using switch case perform the following cases

Step6.1:Case 1 Perform addition

Step6.2:Case 2 Perform subtraction

Step6.3:Case 3 Perform multiplication

Step6.4:Case 4 Perform division

Step6.5:case 5 Perform square operation

Step 7:Terminate the Program

#include<stdio.h>

void main()

int a,b,c;

printf("Enter 3 numbers");

scanf("%d%d%d",&a,&b,&c);

if(a>b)

if(a>c)

printf("a is the greatest");

Prepared by Reviewed By Approved by Dr.K.Sakthivel


A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

else

printf("c is the greatest");

}else

if(b>c)

printf("b is the greatest");

else

printf("C is the greatest");

PROGRAM

#include<stdio.h>

void main()

Prepared by Reviewed By Approved by Dr.K.Sakthivel


A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

int n1,n2,n3,opt;

printf("Enter your Numbers");

scanf("%d%d",&n1,&n2);

printf("1.Addition\n 2.-Subtraction\n 3.*Multiplication\n 4./Division\n5.^square\n");

printf("\nEnter your option:");

scanf("%d",&opt);

switch(opt)

case 1:

n3=n1+n2;

printf("result:%d",n3);

break;

case 2:

n3=n1-n2;

printf("result:%d",n3);

break;

case 3:

n3=n1*n2;

printf("result:%d",n3);

break;

Prepared by Reviewed By Approved by Dr.K.Sakthivel


A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

case 4:

n3=n1/n2;

printf("result:%d",n3);

case 5:

n1=n1^2;

n2=n2^2;

printf("result:%d%d",n1,n2);

break;

OUTPUT

Prepared by Reviewed By Approved by Dr.K.Sakthivel


A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

Prepared by Reviewed By Approved by Dr.K.Sakthivel


A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

Result:

Thus the program was implemented and the output was verified.
Prepared by Reviewed By Approved by Dr.K.Sakthivel
A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

EXERCISE-5

Armstrong number or Not

Aim:

To Write a C Program for finding Armstrong number or not

Reference

Reema Thareja,”Programming in C”,Oxford University Press,Second Edition,2016

List of Apparatus

HARDWARE:

1. Personal Computer/user

SOFTWARE:

Turbo C compiler

Principle

Decision making is about deciding the order of execution of statements based on certain
conditions or repeat a group of statements until certain specified conditions are met.C language
handles decision

Steps

Step1:Start the program

Step2:Include the necessary header files

Step3:Declare the necessary variables

Step4:Enter 3 digit number

Prepared by Reviewed By Approved by Dr.K.Sakthivel


A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

Step5:Perform Armstrong number

Step6:If the result is equal to original number then print Armstrong number else print not
Armstrong number

Step 7:Terminate the Program

PROGRAM

#include<stdio.h>

void main()

int number,originalnumber,remainder,result=0;

printf("Enter a three digit integer:");

scanf("%d",&number);

originalnumber=number;

while(originalnumber!=0)

remainder=originalnumber%10;

result+=remainder*remainder*remainder;

originalnumber/=10;

if(result==number)

printf("%d is an armstrong number.",number);

Prepared by Reviewed By Approved by Dr.K.Sakthivel


A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

else

printf("%d is not an armstrong number",number);

OUTPUT

Result

Thus a Program was implemented and the output was verified

EXERCISE-6
Prepared by Reviewed By Approved by Dr.K.Sakthivel
A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

Aim:

To Write a C Program for perform some operaion set of numbers

Reference

Reema Thareja, “Programming in C”, Oxford University Press, Second Edition,2016

List of Apparatus

HARDWARE:

1. Personal Computer/user

SOFTWARE:

Turbo C compiler

Principle

An array is a collection of data that holds fixed number of values of same type. Arrays have 0 as
the first index not 1.In this example, mark[0]

If the size of an array is n, to access the last element,(n-1) index is used. In this example, mark[4]

Steps

Step1:Start the program

Step2:Given a set of numbers like<10,36,54,89,12,27>,find the sum of weights based on the


following conditions

Step3:5 if it is a Perfect Cube.

Step4:2 if it is a multiple of 4 and divisible by 6

Prepared by Reviewed By Approved by Dr.K.Sakthivel


A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

Step5:3 if it is a Prime number

Step 6:Sort the numbers Based on the weight in the increasing order as shown below<10,its
weight>,<36,its weight><89.its weight>.’,

Step 7:Display the values

Step 8:Terminate the Program

#include<stdio.h>

#include<math.h>

#include<conio.h>

int prime(intnum)

inti,flag=0;

for(i=2;i<num;i++)

if(num%i==0)

flag=1;

break;

Prepared by Reviewed By Approved by Dr.K.Sakthivel


A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

return flag;

intgetWeight(int n)

int w=0;

floatcube_root=pow(n,1.0/3.0);

if(cube_root==ceil(cube_root))

w+=5;

if(n%4==0&&n%6==0)

w+=4;

if(prime(n)==0)

w+=3;

return w;

int main()

intnums[15];

clrscr();

intws[15];

inti,j,t,n;
Prepared by Reviewed By Approved by Dr.K.Sakthivel
A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

printf("Enter numberof numbers:");

scanf("%d",&n);

printf("\n enter numbers:");

for(i=0;i<n;i++)

scanf("%d",&nums[i]);

for(i=0;i<n;i++)

ws[i]=getWeight(nums[i]);

printf("\n Before sorting:\n");

for(i=0;i<n;i++)

printf("%d:%d\t",nums[i],ws[i]);

for(i=0;i<n;i++)

for(j=0;j<n-i-1;j++)

if(ws[j]>ws[j+1])

t=ws[j+1];

ws[j+1]=ws[j];

ws[j]=t;

t=nums[j+1];

nums[j+1]=nums[j];

nums[j]=t;
Prepared by Reviewed By Approved by Dr.K.Sakthivel
A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

printf("\nsorted:\n");

for(i=0;i<n;i++)

printf("%d%d\t",nums[i],ws[i]);

return 0;

getch();

OUTPUT

Prepared by Reviewed By Approved by Dr.K.Sakthivel


A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

Result:

Thus a Program was implemented and the output was verified.

Prepared by Reviewed By Approved by Dr.K.Sakthivel


A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

EXERCISE-7

Find Average Height


Aim

To Write A C Program Populate an array with height of persons and find how many persons are
above the average height

Reference

Reema Thareja, “Programming in C”, Oxford University Press, Second Edition,2016

List of Apparatus

HARDWARE:

1. Personal Computer/user

SOFTWARE:

Turbo C compiler

Principle

Loops are user in programming to repeat a specific block until some end condition is met. There
are three loops in C programming:

For loop

While loop

do…while loop

Prepared by Reviewed By Approved by Dr.K.Sakthivel


A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

Steps:

Step1:Start the Program

Step2:Include the necessary header files.

Step3:Declare the necessary variables

Step4:Read number of persons

Step5:Find out the avg height

Step6:Finding out the number of persons above average

Step7:Terminate the Program

#include <stdio.h>

#include<conio.h>

void main ()

clrscr();

inti,n,count =0;

floatperson_h[100];

float sum=0,avg;

printf("enter the number of persons:");

scanf("%d",&n);

for(i=0;i<n;i++)

{
Prepared by Reviewed By Approved by Dr.K.Sakthivel
A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

printf("\nenterperson_h[%d]=",i);

scanf("%f",&person_h[i]);

sum=sum+person_h[i];

avg=sum/n;

for(i=0;i<n;i++)

if(avg<person_h[i])

count++;

printf("\naverage height ofperson =%f",avg);

printf("\nnumber of persons above average height =%d",count);

getch();

Prepared by Reviewed By Approved by Dr.K.Sakthivel


A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

Result:

Thus the Program was implemented and the output was verified.

Prepared by Reviewed By Approved by Dr.K.Sakthivel


A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

EXERCISE-8

Find BMI
Aim

To write a C Program Populate a two dimensional array with height and weight of person and
compute the Body Mass Index of the Individuals

Reference

Reema Thareja, “Programming in C”, Oxford University Press, Second Edition,2016

List of Apparatus

HARDWARE:

1. Personal Computer/user

SOFTWARE:

Turbo C compiler

Principle

An array is a collection of data that holds fixed number of values of same type. Arrays have 0 as
the first index not 1.In this example, mark[0]

If the size of an array is n, to access the last element,(n-1) index is used. In this example, mark[4]

Populate an array with height of persons and find how many persons are above the average
height

Steps:

Step1:Start the Program


Prepared by Reviewed By Approved by Dr.K.Sakthivel
A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

Step2:Include the necessary header files

Step3:Declare the necessary variables

Step4:Readthe weight and height of certain persons

Step5:Calculate t=(w/h*h)

Step6:for each t check for starvation,underweigh,weight

Step 7:Terminate the program

Program

#include<stdio.h>

#include<conio.h>

void main()

inti,n;

floatperson_hw[100][2];

floatbmi;

printf("enter the number of persons:");

scanf("%d",&n);

for(i=0;i<n;i++)

{printf("\nenter persons height (in meter)and weight (in kg)[%d]=",i+1);

scanf("%f%f", &person_hw[i][0],&person_hw[i][1]);

bmi =person_hw[i][1]/(person_hw[i][0]*person_hw[i][0]);
Prepared by Reviewed By Approved by Dr.K.Sakthivel
A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

printf("\nbody mass index of person %d=%f",i+1,bmi);

getch();

}}

OUTPUT

Result

Thus the program was implemented and the output was verified.
Prepared by Reviewed By Approved by Dr.K.Sakthivel
A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

EXERCISE-9

Aim:

To write a C Program Given a String “a$bcd./fg”find its reverse without changing the position of
special characters.(Example input:a@gh%;j and output:j@hg%;a)

Reference

Reema Thareja, “Programming in C”, Oxford University Press, Second Edition,2016

List of Apparatus

HARDWARE:

1. Personal Computer/user

SOFTWARE:

Turbo C compiler

Principle

Array of characters is called a string.A String is terminated by a null characters /0.

String are declared in a similar manner as arrays.only difference is that,String are of char type

Steps:

Step1:Start the Program

Step2:Include the header files

Step 3:Declare variable using pointers

Step4:Get the string

Step 5:Reverse the String using strrev(),strcmp(),swap() functions

Prepared by Reviewed By Approved by Dr.K.Sakthivel


A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

Step 6:Do not swap any special characters.

Step7:Print the Reverse String

Step 8:Terminate the Program.

Program

#include<stdio.h>

#include<string.h>

#include<conio.h>

int main()

char s[20],s1[20]={"00000000000000000000"};

inti,j,length,flag;

printf("\nEnter the String");

gets(s);

length=strlen(s);

for(i=0;i<length;i++)

if(!((s[i]>='a'&&s[i]<='z')||(s[i]>='A'&&s[i]<='Z')||(s[i]>='0'&&s[i]<='9')))

s1[i]=s[i];

j=length-1;
Prepared by Reviewed By Approved by Dr.K.Sakthivel
A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

for(i=0;i<length;i++)

flag=0;

if(((s[i]>='a'&&s[i]<='z')||(s[i]>='A'&&s[i]<='Z')||(s[i]>='0'&&s[i]<='9')))

do

if(s1[j]=='0')

s1[j]=s[i];

flag=1;

j--;

else

j--;

while(flag!=1);

s1[length]='\0';

printf("\nReverse String:%s\n",s1);

return(0);
Prepared by Reviewed By Approved by Dr.K.Sakthivel
A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

getch();

Result:

Thus a program was implemented and the output was verified.

EXERCISE-10

Number Conversion Process


Prepared by Reviewed By Approved by Dr.K.Sakthivel
A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

Aim:

To write a c Program Convertthe given decimal number into binary,octal and hexadecimal
numbers using user defined functions

Reference

Reema Thareja, “Programming in C”, Oxford University Press, Second Edition,2016

List of Apparatus

HARDWARE:

1. Personal Computer/user

SOFTWARE:

Turbo C compiler

Principle

C uses a variety of number types—different numeric data types, so to speak. Table 1 lists them
all, along with other statistical information.

The table is something you’ll refer to now and again because only the truly insane would
memorize it all.

By using user defined Function

Function elements

1.Function declaration

2.Function definition

3.Function calling

Algorithm to convert Decimal to Binary number


Prepared by Reviewed By Approved by Dr.K.Sakthivel
A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

Divide the input decimal number by 2 and store the remainder

Store the quotient back to the input number variable.

Repeat this process till quotient becomes zero

Equivalent binary number will be the remainders in above process in reverse order.

Steps:

Step1:Start the Program

Step2:Include the necessary header files.

Step3:Declare the necessary avriables,function

Step4:Find out the Hexadecimal,octal,binary number

Step5:Print the values

Step6:Terminate the Program

PROGRAM

#include<stdio.h>

longdecimalToBinary(long n);

longdecimalToOctal(long n);

longdecimalToHexadecimal(long n);

int main()

long decimal;

printf("Enter a decimal number:");


Prepared by Reviewed By Approved by Dr.K.Sakthivel
A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

scanf("%ld",&decimal);

printf("\n Binary number of %ld is %ld",decimal,decimalToBinary(decimal));

printf("\n Octal number of %ld is %ld",decimal,decimalToOctal(decimal));

printf("\n Hexadecimal number of %ld is %ld",decimal,decimalToHexadecimal(decimal));

return 0;

longdecimalToBinary(long n)

int remainder;

long binary=0,i=1;

while(n!=0)

remainder=n%2;

n=n/2;

binary=binary+(remainder*i);

i=i*10;

return binary;

longdecimalToOctal(long n)
Prepared by Reviewed By Approved by Dr.K.Sakthivel
A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

int remainder;

long octal=0,i=1;

while(n!=0)

remainder=n%8;

n=n/8;

octal=octal+(remainder*i);

i=i*10;

return octal;

longdecimalToHexadeciaml(long n)

int remainder;

long hexadecimal=0,i=1;

while(n!=0)

remainder=n%16;

n=n/16;
Prepared by Reviewed By Approved by Dr.K.Sakthivel
A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

hexadecimal=hexadecimal+(remainder*i);

i=i*10;

return hexadecimal;

OUTPUT:

Prepared by Reviewed By Approved by Dr.K.Sakthivel


A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

Result

Thus the Program was implemented and the output was verified.

Prepared by Reviewed By Approved by Dr.K.Sakthivel


A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

EXERCISE-11

Built In Functions
AIM

To Write a C Program From a given paragraph perform the following using built in functions

Principle

Steps:

a.Find the total number of words

b.Capitalize the first word of each sentence.

c.Replace a given word with another word.

Program:

#include<stdio.h>

#include<ctype.h>

#include<string.h>

#define MAX 100

void capitalize(char *);

intwordCount(char *);

void replace(char *);

int main()

{
Prepared by Reviewed By Approved by Dr.K.Sakthivel
A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

charpara[MAX]={0};

printf("Enter a Paragraph:");

scanf("%[^\n]s",para);

capitalize(para);

printf("Enter a Capitalize Paragraph is:%s",para);

printf("\n Number of words in given paragraph are:%d",wordCount(para));

replace(para);

printf("New Paragraph is:%s",para);

return 0;

void capitalize(char *p)

int i=0;

do

if(i==0||(p[i-1]==''&&(p[i-2]=='.'||p[i-2]=='?')))

do

p[i]=toupper(p[i]);
Prepared by Reviewed By Approved by Dr.K.Sakthivel
A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

i++;

while(p[i]!='');

i++;

while(p[i]!='\0');

intwordCount(char *p)

inti,count=0;

for(i=0;p[i]!='\0';i++)

if(p[i]==``)

count++;

return count+1;

void replace(char *p)

{
Prepared by Reviewed By Approved by Dr.K.Sakthivel
A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

char word[20],rpword[20];

charstr[10],rp[100],pp[100];

int i=0,j=0,k,len,length;

printf("Enter the WORD to be replaced");

scanf("%s",word);

printf("Enter the WORD the %s to be replaced:",word);

scanf("%s",rpword);

length=strlen(p);

for(k=0;k<length;k++)

j=0;

do

if(p[k+j]!=''||p[k+j]!='.'||p[k+j]!='?')

str[j]=p[k+j];

j++;

else

{
Prepared by Reviewed By Approved by Dr.K.Sakthivel
A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

j++;

while((p[k+j]!='')&&(p[k+j]!='.')&&(p[k+j]!='?')&&(p[k+j]!='\0'));

str[j]='\0';

if(strcmp(str,word)==0)

len=strlen(str);

strncpy(pp,p,k);

strncpy(rp,p+k+len,length-k-len);

strcpy(p,pp);

strcat(p,rpword);

strcat(p,rp);

/*for(i=0;i<len;i++)

p[k+i]=rpword[i];

*/

}}}

Result
Prepared by Reviewed By Approved by Dr.K.Sakthivel
A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

Thus the Program was executed and output was verified

EXERCISE-12

Towers of Hanoi
Aim:

To write a C Program solve towers of Hanoi using recursion

Reference

Reema Thareja, “Programming in C”, Oxford University Press, Second Edition,2016

List of Apparatus

HARDWARE:

1. Personal Computer/user

SOFTWARE:

Turbo C compiler

Principle:

Rules of Tower of Hanoi:

Only a single disc is allowed to be transferred at a time.

Each transfer or move should consist of taking the upper disk fom one of the stacks and then
placing it the of another stack i.e.only a topmost disk on the stack can be moved.

Larger disk cannot be placed over smaller disk;placing of disk should be in increasing prder.

SOLVE TOWERS OF HANOI USING RECURSION

Prepared by Reviewed By Approved by Dr.K.Sakthivel


A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

This Program uses recursive function and solves the towers of Hanoi.The tower

Mathematical puzzle .it contains of three rods and a number of desks of different sizes which
can slide onto any rod .

The puzzle starts with the disks in a neet stack in assending order of size on one rod,thesmallestat
the top we have to obtain the same strack

On the third rod .here is the source cord of the c program for solving towers of Hanoi.

Steps:
Step1:Start the Program

Step2:Include the necessary header files

Step3:Declare necessary variables

Step4:Read the number of disk.

Step 5Transfer the from one stack to another

Step6:Each move of the disk should be placed on the top of another stack.

Step7:Terminate the program

Program:

#include<stdio.h>

#include<conio.h>

Intmain()

intnum;

Prepared by Reviewed By Approved by Dr.K.Sakthivel


A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

printf("Enter the numbers of disks");

scanf("%d",&num);

printf("the sequence of moves involved in the tower of Hanoi are:\n");

towers(num,'A','C','B');

return 0;

void towers(intnum,charfrompeg,chartopeg,charauxpeg)

if(num==1)

printf("\n moves disk 1 from peg %c to peg %c",frompeg,topeg);

return;

towers(num-1,frompeg,auxpeg,topeg);

printf("\n Move disk %d from peg %c to peg %c",num,frompeg,topeg);

towers(num-1,auxpeg,topeg,frompeg);

OUTPUT

Prepared by Reviewed By Approved by Dr.K.Sakthivel


A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

Result:
Thus the program was implemented and the output was verified

Prepared by Reviewed By Approved by Dr.K.Sakthivel


A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

EXERCISE-13

Pass by Reference
Aim

To Write the program sort the list of numbers using pass by reference

Reference

Reema Thareja, “Programming in C”, Oxford University Press, Second Edition,2016

List of Apparatus

HARDWARE:

1. Personal Computer/user

SOFTWARE:

Turbo C compiler

Principle

Sorting is any process of arranging items systematically,and has two common,yet distinct
meanings:ordering:arranging items in a sequence ordered by some
criterion;categorizing :grouping items with similar properties

The arranging in an ordered sequence is called “Sorting”.Sorting is a a common operation in


many applications,and efficient algorithms to perform it have been developed.

The most common uses of sorted sequences are:

Making lookup or search efficient

Making merging of sequences efficient

Enable processing of data ina a define d order


Prepared by Reviewed By Approved by Dr.K.Sakthivel
A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

program:

#include<stdio.h>

#include<conio.h>

void sort(int *);

int main()

int i;

int a[10]={45,35,23,12,78,67,43,90,88,33};

sort(a);

printf("Sorted List is:");

for(i=0;i<10;i++)

printf("%d",a[i]);

return 0;

void sort(int *array)

intc,d,swap;

for(c=0;c<9;c++)
Prepared by Reviewed By Approved by Dr.K.Sakthivel
A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

for(d=0;d<9-c;d++)

if(array[d]>array[d+1])

swap=array[d];

array[d]=array[d+1];

array[d+1]=swap;

getch();

OUTPUT

Prepared by Reviewed By Approved by Dr.K.Sakthivel


A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

Result:

Thus the Program was implemented nd the output was verified.

Prepared by Reviewed By Approved by Dr.K.Sakthivel


A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

EXERCISE-14

Employee Salary Slip


Aim

To write a C Program Generate salary slip of employees using structures and pointers

Reference

Reema Thareja, “Programming in C”, Oxford University Press, Second Edition,2016

List of Apparatus

HARDWARE:

1. Personal Computer/user

SOFTWARE:

Turbo C compiler

Principle:

A struct in the C Programming language (and many derivatives) is a composite data type
declaration that defines a physically grouped list od variables to

Be placed under one name in a block of memory, allowing the different variables to be accessed
via a single pointer, or the struct declared name which

Returns the same address. The struct can contain many other complex and simple data types in
an association, so is a natural organizing type for records like the mixed data types in lists of
directory entries reading a hard drive(file length, name type, extension, physical
( cylinder,disk,head indexes) address, etc.),or other mixed record type(patient names, assress,
telephone… insurance codes, balance, etc.)

Prepared by Reviewed By Approved by Dr.K.Sakthivel


A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

Steps:

Step1:Start the Program

Step2:Include the necessary header files .

Step3:Declare Structure with necessary members

Step4:Print the name and salary details by using struct

Step5:Terminate the Program

Program

#include<stdio.h>

#include<conio.h>

struct employee

int no;

char name[10];

intdesignationNo;

intdaysWorked;

};

void main()

int i;
Prepared by Reviewed By Approved by Dr.K.Sakthivel
A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

struct employee *employeePtr;

intdaySal[4]={2000,1000,750,500};

struct employee emp[12]={{1,"GANESH",1,25},{2,"MAHESH",1,30},{3,"SURESH",2,28},


{4,"KALPESH",2,26},{5,"RAHUL",2,24},{6,"SUBBU",2,25},{7,"RAKESH",2,23},
{8,"ATUL",2,22},{9,"DHARMESH",3,26},{10,"AJAY",3,26},{11,"ABDUL",3,27},
{12,"RASHMI",4,29}};

employeePtr=&emp[0];

for(i=0;i<12;i++)

printf("SALARY Slip for employee[%d]",employeePtr->no);

printf("\t%s",employeePtr->name);

printf("\tSalary:%d\n",daySal[employeePtr->designationNo-1]*employeePtr->daysWorked);

employeePtr++;

OUTPUT

Prepared by Reviewed By Approved by Dr.K.Sakthivel


A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

Prepared by Reviewed By Approved by Dr.K.Sakthivel


A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

EXERCISE-15

Student Internal Marks


Aim:

To write a C Program to Compute internal mark of students for five different subjects using
structures and functions

Reference

Reema Thareja, “Programming in C”, Oxford University Press, Second Edition,2016

List of Apparatus

HARDWARE:

1. Personal Computer/user

SOFTWARE:

Turbo C compiler

Principle

Pointers in C are easy and fun to learn. Some C programming tasks are performed mor easily
with pointers, and other tasks, such as dynamic memory allocation, cannot be performed without
using pointers. So it becomes necessary to learn pointers to become a perfect C programmer.
Let’s start learning them in simple and easy steps.

As you know,every variable is a memory location and memory location has its address defined
which can be accessed using ampersand(&) operator, which denotts an address in memory.

Steps:

Step 1:Start the program


Prepared by Reviewed By Approved by Dr.K.Sakthivel
A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

Step2:Include the necessary header files

Step3:Declare structure and necessary variables

Step 4:Enter mark in all subjects

Step5:Calculate total amrks

Step6:Print total

Step7:Terminate the program

PROGRAM:

#include<stdio.h>

#include<conio.h>

#define S 50

struct student

char name[30];

introllno;

int sub[5];

};

voidinternal_M(struct student s[],intnum)

inti,j,total;
Prepared by Reviewed By Approved by Dr.K.Sakthivel
A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

for(i=0;i<num;i++)

total=0;

for(j=0;j<5;j++)

total=total+s[i].sub[j];

printf("Total marks obtained by student %s are %d\n",s[i].name,total);

int main()

clrscr();

inti,j,n;

struct student st[S];

printf("Enter how many students:");

scanf("%d",&n);

for(i=0;i<n;i++)

printf("Enter name and roll number for student %d",i+1);


Prepared by Reviewed By Approved by Dr.K.Sakthivel
A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

scanf("%s",&st[i].name);

scanf("%d",&st[i].rollno);

for(j=0;j<5;j++)

printf("Enter marks of student %d for subject %d:",i+1,j+1);

scanf("%d",&st[i].sub[j]);

internal_M(st,n);

return 0;

OUTPUT

Prepared by Reviewed By Approved by Dr.K.Sakthivel


A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

Result:Thus the Program was implemented and the output was verified

Prepared by Reviewed By Approved by Dr.K.Sakthivel


A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

EXERCISE-16

Balance Checking Using File

Aim

Count the number of account holders whose balance is less than the minimum balance using
sequential access file

Reference

Reema Thareja, “Programming in C”, Oxford University Press, Second Edition,2016

List of Apparatus

HARDWARE:

1. Personal Computer/user

SOFTWARE:

Turbo C compiler

Principle:

Steps:

Step1:Start the program

Step2:Include the necessary header files

Step3:Create file directory filename.txt

Step4.By using fopen() to view the file information

Step5:Read each ACC no,Balance doing the operations append,finding,display

Prepared by Reviewed By Approved by Dr.K.Sakthivel


A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

Step6:Terminate the Program

PROGRAM

#include<stdio.h>

#include<conio.h>

#include<stdlib.h>

struct customer

char name[20];

intacct_num;

floatacct_balance;

};

int main()

{FILE *fp;

struct customer cust;

float min=5000;

fp=fopen("accounts.txt","w");

if(fp==NULL)

{printf("Error opening accounts.txt\n\n");

exit(1);

}
Prepared by Reviewed By Approved by Dr.K.Sakthivel
A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

printf("\nEnter accounts information\n\n");

int choice=1;

do

printf("\nName:");

scanf("%s",cust.name);

printf("Acct Num:");

scanf("%d",&cust.acct_num);

printf("Balance");

scanf("%f",&cust.acct_balance);

fwrite(&cust,sizeof(struct customer),1,fp);

printf("Press 1 to enter one more entry:\n");

scanf("%d",&choice);

while(choice==1);

fclose(fp);

fp=fopen("accounts.txt","r");

if(fp==NULL)

printf("Error opening accounts.txt\n\n");


Prepared by Reviewed By Approved by Dr.K.Sakthivel
A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

exit(1);

else

printf("\n File opened for reading :accounts.txt\n\n");

while(fread(&cust,sizeof(struct customer),1,fp))

if(cust.acct_balance<=min)

printf("/nName=%10s AcctNum=%8d Balance=%8.2f\


n",cust.name,cust.acct_num,cust.acct_balance);

}}

fclose(fp);

return 0;

OUTPUT

Prepared by Reviewed By Approved by Dr.K.Sakthivel


A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh
LABORATORY ACTIVITY MANUAL

P.s.r.r college of engineering

Doc No Issue No Issue Date Rev Rev Date Section No:0.0


No
PSRR/CSE/C/R21/ 01 15-04-22

Result

Thus the program was implemented and the output was verified.

MINI PROJECT

RAILWAY RESERVATION SYSTEM

Prepared by Reviewed By Approved by Dr.K.Sakthivel


A.RAJALAKSHMI HOD/CSE PRINCIPAL
AP/CSE Dr.S.Erana Veerappa Dinesh

You might also like