0% found this document useful (0 votes)
31 views34 pages

CPL Lab Record 2023

The document contains the code for several C programming exercises from a lab course. It includes programs to calculate the area and circumference of a circle, find the largest of three numbers, calculate employee payroll details, convert between Celsius and Fahrenheit temperatures, determine if a number is odd or even, positive or negative, and if a year is a leap year. It also includes a basic calculator program and programs to check if a number is an Armstrong number or determine how many persons in an array of heights are above the average height.

Uploaded by

rishipandian2006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views34 pages

CPL Lab Record 2023

The document contains the code for several C programming exercises from a lab course. It includes programs to calculate the area and circumference of a circle, find the largest of three numbers, calculate employee payroll details, convert between Celsius and Fahrenheit temperatures, determine if a number is odd or even, positive or negative, and if a year is a leap year. It also includes a basic calculator program and programs to check if a number is an Armstrong number or determine how many persons in an array of heights are above the average height.

Uploaded by

rishipandian2006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 34

CS8261 - C PROGRAMMING LABORATORY

EX.NO : 1 (A)
DATE : 17.04.2021

PROGRAM TO FIND THE AREA AND CIRCUMFERENCE OF CIRCLE

PROGRAM
#include<stdio.h>
#define PI 3.1415

float area(float r)
{
return PI*r*r;
}
float perimeter(float r)
{
return 2*PI*r;
}

int main()
{
float radius;
printf("Enter the radius of the circle?\n");
scanf("%f",&radius);
printf("area of circle=%.2f",area(radius));
printf("\nCircumference of circle=%.2f",perimeter(radius));
return 0;
}

OUTPUT
Enter the radius of the circle?
12
area of circle=452.38
Circumference of circle=75.40

RESULT:

PANIMALAR ENGINEERING COLLEGE


CS8261 - C PROGRAMMING LABORATORY
EX.NO : 1 (B)
DATE : 17.04.2021

PROGRAM TO FIND THE LARGEST AMONG THE THREE GIVEN


NUMBERS

PROGRAM
#include <stdio.h>
int main()
{
int a,b,c,big;
printf("\nEnter three numbers to find largest:\n");
scanf("%d %d %d",&a, &b, &c);
if(a>b && a>c)
big=a;
else if(b>c)
big=b;
else
big=c;
printf("The Largest number is = %d",big);
return 0;
}
OUTPUT
Enter three numbers to find largest:
10 34 21
The Largest number is = 34

RESULT:

PANIMALAR ENGINEERING COLLEGE


CS8261 - C PROGRAMMING LABORATORY
EX.NO : 1(C)
DATE : 17.04.2021

WRITE A C PROGRAM READ NAME AND BASIC PAY OF AN EMPLOYEE


AND COMPUTE DA,HRA,PF,TAX,GROSS PAY AND NET PAY

PROGRAM
#include<stdio.h>
void main()
{
char ename[30];
float basic,pf,tax,da,hra,gross,net;
printf("\nEnter Employee Name :");
gets(ename);
printf("\nEnter the basic pay : ");
scanf("%f",&basic);
pf=(15/100.0)*basic;
da=(38/100.0)*basic;
tax=(15/100.0)*basic;
hra=(10/100.0)*basic;
gross=basic+da+hra;
net=gross-(pf+tax);
printf("\n DA : %.2f",da);
printf("\n HRA : %.2f",hra);
printf("\n Gross Pay : %.2f",gross);

printf("\n\n PF : %.2f",pf);
printf("\n Tax : %.2f",tax);
printf("\n Net Pay : %.2f",net);
return 0;
}

OUTPUT
Enter Employee Name :Ram Kumar D
Enter the basic pay : 50000
DA : 19000.00
HRA : 5000.00
Gross Pay : 74000.00
PF : 7500.00
Tax : 7500.00
Net Pay : 59000.00

RESULT:

PANIMALAR ENGINEERING COLLEGE


CS8261 - C PROGRAMMING LABORATORY
EX.NO : 1(D)
DATE : 23.04.2021

PROGRAM TO CONVERT THE TEMPERATURE CELSIUS INTO


FAHRENHEIT
PROGRAM
#include<stdio.h>
int main()
{
float c,f;
printf("\nEnter the Celsius value?\n");
scanf("%f",&c);
f=c*9/5+32 ;
printf("\nThe Equal Fahrenheit value is : %.2f",f);
return 0;
}

OUTPUT
Enter the Celsius value?
45

The Equal Fahrenheit value is : 113.00

RESULT:

PANIMALAR ENGINEERING COLLEGE


CS8261 - C PROGRAMMING LABORATORY
EX.NO : 2(A)
DATE : 23.04.2021

PROGRAM TO FIND WHETHER A GIVEN NUMBER IS ODD OR EVEN

PROGRAM
#include<stdio.h>
int main()
{
int n;
printf("Input the number?\n");
scanf("%d",&n);
if(n%2==0)
printf("The given number is Even");
else
printf("The given number is Odd");
return 0;
}

OUTPUT
Input the number?
31
The given number is Odd

RESULT:

PANIMALAR ENGINEERING COLLEGE


CS8261 - C PROGRAMMING LABORATORY
EX.NO : 2(B)
DATE : 23.04.2021

PROGRAM TO FIND WHETHER A GIVEN NUMBER IS POSITIVE OR


NEGATIVE OR ZERO

PROGRAM
#include<stdio.h>
int main()
{
int n;
printf("Input the number?\n");
scanf("%d",&n);
if (n>0)
printf("The given number is Positive");
else if(n==0)
printf("The given number is Zero");
else
printf("The given number is Negative");

return 0;
}

OUTPUT
Input the number?
32
The given number is Positive

RESULT:

PANIMALAR ENGINEERING COLLEGE


CS8261 - C PROGRAMMING LABORATORY
EX.NO : 3
DATE : 24-04-2021

PROGRAM PROGRAM TO FIND WHETHER THE GIVEN YEAR IS LEAP


YEAR OR NOT
PROGRAM
#include<stdio.h>
int main()
{
int year;
printf("Enter the year to find whether leap year or not?\n");
scanf("%d",&year);
if(year%400==0 || (year%4==0 && year%100!=0) )
printf("\n%d is leap year",year);
else
printf("\n%d is not leap year",year);
return 0;
}
OUTPUT
Enter the year to find whether leap year or not?
1900

1900 is not leap year


RESULT:

PANIMALAR ENGINEERING COLLEGE


CS8261 - C PROGRAMMING LABORATORY
EX.NO : 4
DATE : 24-04-2021

DESIGN A CALCULATOR TO PERFORM THE OPERATIONS, NAMELY,


ADDITION, SUBTRACTION, MULTIPLICATION, DIVISION AND SQUARE
OF A NUMBER
PROGRAM
#include <stdio.h>
#include <math.h>
int main()
{
char op;
float num1, num2, result=0.0f;
printf("WELCOME TO SIMPLE CALCULATOR\n");
printf("--------------------------------------------------\n");
printf("\nPress Ctrl + C to terminate program");
while(1)
{
printf("\nEnter firstNumber [+ - * / ^] secondNnumber\n");
scanf("%f %c %f", &num1, &op, &num2);
switch(op)
{
case '+': result = num1 + num2;
break;
case '-': result = num1 - num2;
break;
case '*': result = num1 * num2;
break;
case '/': result = num1 / num2;
break;
case '^': result = pow(num1,num2);
break;
}
printf("%f\n",result);
}
return 0;
}

OUTPUT
WELCOME TO SIMPLE CALCULATOR
--------------------------------------------------
Press Ctrl + C to terminate program
Enter firstNumber [+ - * / ^] secondNnumber
23+11.5
34.500000

PANIMALAR ENGINEERING COLLEGE


CS8261 - C PROGRAMMING LABORATORY
Enter firstNumber [+ - * / ^] secondNnumber
3*4
12.000000

RESULT:

PANIMALAR ENGINEERING COLLEGE


CS8261 - C PROGRAMMING LABORATORY
EX.NO : 5
DATE : 07.05.2021

CHECK WHETHER A GIVEN NUMBER IS ARMSTRONG NUMBER OR


NOT

PROGRAM
#include<stdio.h>
#include<math.h>
int main()
{
int n,x,p=0,sum=0,r;
printf("Enter the number: ");
scanf("%d",&n);
x=n;
while(x!=0)
{
p++;
x=x/10;
}
x=n;
while(x!=0)
{
r=x%10;
sum=sum+pow(r,p);
x=x/10;

}
if(n==sum)
printf("\n%d is armstrong",n);
else
printf("\n%d is not armstrong",n);
return 0;
}
OUTPUT

Enter the number: 153


153 is Armstrong
=============rerun==================
Enter the number: 81
81 is not armstrong

RESULT:

PANIMALAR ENGINEERING COLLEGE


CS8261 - C PROGRAMMING LABORATORY
EX.NO : 6
DATE : 07.05.2021

GIVEN A SET OF NUMBERS LIKE <10, 36, 54, 89, 12, 27>, FIND SUM OF
WEIGHTS BASED ON THE FOLLOWING CONDITIONS:
 5 if it is a perfect cube.
 4 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>

PROGRAM
#include<stdio.h>
#include<math.h>
typedef struct
{
int number,weight;
} SumWeight;
int main()
{
static SumWeight w [50],tmp;
int n,i,j,isPrime,cube_root;
printf("How many numbers your want to read?\n");
scanf("%d",&n);
printf("input %d number one by one:\n",n);
for(i=0;i<n;i++)
{
scanf("%d",&w [i].number);
cube_root = pow(w [i].number, 1.0 / 3.0);
if (cube_root * cube_root * cube_root == w [i].number)
w [i].weight=5;

if( w [i].number%4==0 && w [i].number%6 == 0)


w [i].weight+=4;

isPrime=1;
for(j=2;j<w [i].number-1;j++)
if(w [i].number%j==0)
{
isPrime=0;
break;
}
if(isPrime==1)
w [i].weight+=3;

PANIMALAR ENGINEERING COLLEGE


CS8261 - C PROGRAMMING LABORATORY
}
for(i=0;i<n-1;i++)
for(j=i+1;j<n;j++)
if(w [i].weight > w [j].weight)
{
tmp=w [i];
w [i]=w [j];
w [j]=tmp;
}

printf("numbers based on it weights:\n");


for(i=0;i<n;i++)
printf("<%d,%d>,",w [i].number,w [i].weight);
printf("\b ");
return 0;
}

OUTPUT
How many numbers your want to read?
4
input 4 number one by one:
10
11
12
27
numbers based on it weights:
<10,0>,<11,3>,<12,4>,<27,5>

RESULT:

PANIMALAR ENGINEERING COLLEGE


CS8261 - C PROGRAMMING LABORATORY
EX.NO : 7
DATE : 21.05.2021

POPULATE AN ARRAY WITH HEIGHT OF PERSONS AND FIND HOW


MANY PERSONS ARE ABOVE THE AVERAGE HEIGHT

PROGRAM
#include<stdio.h>
int main()
{
int n,i,count=0;
float height[50],avgheight=0;
printf("Enter how many persons? ");
scanf("%d",&n);
printf("Enter persons height in CM:\n");
for(i=0;i<n;i++)
{
printf("Person %d: ",i+1);
scanf("%f",&height[i]);
avgheight += height[i];
}
avgheight = avgheight / n;
printf("\naverage height = %f",avgheight);

for(i=0;i<n;i++)
if(height[i]>avgheight)
count += 1;
printf("\ntotal number of persons above average = %d",count);
return 0;
}

OUTPUT
Enter how many persons? 6
Enter persons height in CM:
Person 1: 167.5
Person 2: 170
Person 3: 188
Person 4: 155
Person 5: 160
Person 6: 157
average height = 166.250000
total number of persons above average = 3

RESULT:

PANIMALAR ENGINEERING COLLEGE


CS8261 - C PROGRAMMING LABORATORY
EX.NO : 8
DATE : 21.05.2021

POPULATE A TWO DIMENSIONAL ARRAY WITH HEIGHT AND


WEIGHT OF PERSONS AND COMPUTE THE BODY MASS INDEX OF THE
INDIVIDUALS

The formula is BMI = kg/m2 where kg is a person's weight in kilograms and


m2 is their height in metres squared. A BMI of 25.0 or more is overweight,
while the healthy range is 18.5 to 24.9.

PROGRAM
#include<stdio.h>
#include<math.h>

int main()
{
int n,i;
float WtHt[50][2],BMI;
printf("Enter how many persons? ");
scanf("%d",&n);
printf("Enter persons weight in KG, height in CM:\n");
for(i=0;i<n;i++)
{
printf("Person %d: ",i+1);
scanf("%f",&WtHt[i][0]);
scanf("%f",&WtHt[i][1]);
}

printf("\nPersonNo Weight Height BMI");


for(i=0;i<n;i++)
{
BMI=WtHt[i][0] / pow(WtHt[i][1]/100.0,2);
printf("\n%8d %7.2f %7.2f %7.2f",i+1,WtHt[i][0],WtHt[i][1],BMI);
}
return 0;
}
OUTPUT
Enter how many persons? 6
Enter persons weight in KG, height in CM:
Person 1: 200 180
Person 2: 70.5 167.3
Person 3: 100 172
Person 4: 77 182

PANIMALAR ENGINEERING COLLEGE


CS8261 - C PROGRAMMING LABORATORY
Person 5: 89 169
Person 6: 90 179

PersonNo Weight Height BMI


0 200.00 180.00 61.73
1 70.50 167.30 25.19
2 100.00 172.00 33.80
3 77.00 182.00 23.25
4 89.00 169.00 31.16
5 90.00 179.00 28.09

RESULT:

PANIMALAR ENGINEERING COLLEGE


CS8261 - C PROGRAMMING LABORATORY
EX.NO : 9
DATE : 22.05.2021

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)

PROGRAM
#include<stdio.h>
#include<string.h>
#include<ctype.h>
int main()
{
int i,j;
char s[60],ch;
printf("Enter String?\n");
gets(s);
for(i=0,j=strlen(s)-1;i<j;i++,j--)
{
while(!isalnum(s[i]) && i<j)
i++;
while(!isalnum(s[j]) && i<j)
j--;
if(i>=j)
break;

ch=s[i];
s[i]=s[j];
s[j]=ch;
}

printf("\nThe reversed string is %s",s);


return 0;
}

OUTPUT
Enter String?
a@gh%;j

The reversed string is j@hg%;a

RESULT:

PANIMALAR ENGINEERING COLLEGE


CS8261 - C PROGRAMMING LABORATORY
EX.NO : 10
DATE : 28.05.2021

CONVERT THE GIVEN DECIMAL NUMBER INTO BINARY, OCTAL AND


HEXADECIMAL NUMBERS USING USER DEFINED FUNCTIONS

PROGRAM TO CONVERT FROM DECIMAL TO BINARY


#include<stdio.h>
#include<string.h>
void Dec_To_Bin(long n,char b[])
{
int i=0;
char set[]="01";

while(n!=0)
{
b[i]=set[n%2];
n=n/2;
i++;
}
b[i]='\0';
strrev(b);
}

int main()
{
long dec;
char bin[20];
printf("Enter Decimal Number to convert to Binary?\n");
scanf("%ld",&dec);
Dec_To_Bin(dec,bin);
printf("\nThe binary equivalent is %s",bin);
return 0;
}

OUTPUT
Enter Decimal Number to convert to Binary?
20

The binary equivalent is 10100

PROGRAM TO CONVERT FROM DECIMAL TO OCTAL


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

PANIMALAR ENGINEERING COLLEGE


CS8261 - C PROGRAMMING LABORATORY
void Dec_To_Oct(long n, char o[])
{
int i=0;
char set[]="01234567";

while(n!=0)
{
o[i]=set[n%8];
i=i+1;
n=n/8;
}
o[i]='\0';
strrev(o);
}

int main()
{
long dec;
char oct[20];
printf("Enter Decimal Number to convert to Octal?\n");
scanf("%ld",&dec);
Dec_To_Oct(dec,oct);
printf("\nThe Octal equivalent is %s",oct);
return 0;
}

OUTPUT
Enter Decimal Number to convert to Octal?
105

The Octal equivalent is 151

PROGRAM TO CONVERT FROM DECIMAL TO HEXADECIMAL


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

void Dec_To_Hex(long n,char h[])


{
int i=0;
char set[]="0123456789ABCDEF";

while(n!=0)
{
h[i++]=set[n%16];
n=n/16;

PANIMALAR ENGINEERING COLLEGE


CS8261 - C PROGRAMMING LABORATORY
}
h[i]='\0';
strrev(h);
}

int main()
{
long dec;
char hex[20];
printf("Enter Decimal Number to convert to Hexadecimal?\n");
scanf("%ld",&dec);
Dec_To_Hex(dec,hex);
printf("\nThe Hex equivalent is %s",hex);
return 0;
}

OUTPUT
Enter Decimal Number to convert to Hexadecimal?
109

The Hex equivalent is 6D

RESULT:

PANIMALAR ENGINEERING COLLEGE


CS8261 - C PROGRAMMING LABORATORY
EX.NO : 11
DATE : 11.06.2021

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

PROGRAM (A)
/* find total number of words in a given paragraph */
#include<stdio.h>
#include<ctype.h>
int main()
{
int word_count=1,i=0;
char s[500];
printf("Enter the paragraph:\n");
gets(s);
while(s[i]!='\0')
{
if((s[i]==' ' || s[i]=='\t' || s[i]=='\n') &&
(tolower(s[i+1])>='a' && tolower(s[i+1])<='z'))
word_count++;
i++;
}
printf("\nTotal number of words in a given paragraph is %d",word_count);
return 0;
}
OUTPUT
Enter the paragraph:
This is first sentence. This is second sentence. Last sentence.

Total number of words in a given paragraph is 10

PROGRAM (B)
/* make first character of every sentence upper case */
#include<stdio.h>
#include<ctype.h>

int main()
{
int i=2;
char s[500];
printf("Enter the paragraph:\n");
gets(s);

PANIMALAR ENGINEERING COLLEGE


CS8261 - C PROGRAMMING LABORATORY
s[0]=toupper(s[0]);
while(s[i]!='\0')
{
if((s[i]>='a' && s[i]<='z') && s[i-1]==' ' && s[i-2]=='.')
s[i]=toupper(s[i]);
if((s[i]>='a' && s[i]<='z') && s[i-1]=='.')
s[i]=toupper(s[i]);
i++;
}

printf("\nNow the paragraph:\n%s",s);


return 0;
}
OUTPUT
Enter the paragraph:
this is first sentence. it is second sentence. last sentence.

Now the paragraph:


This is first sentence. It is second sentence. Last sentence.

PROGRAM (C)
/* find and replace */
#include<stdio.h>
#include<ctype.h>
#include<string.h>

int main()
{
int i=0;
char s[500],find[20],replace[20],result[500];
char *p1,*p2;
printf("Enter the paragraph:\n");
gets(s);
printf("Enter the text to find:\n");
gets(find);
printf("Enter the text to replace:\n");
gets(replace);

p1=s;

while(*p1!='\0')
{
p2=strstr(p1,find);
if(p2!=0)
{

PANIMALAR ENGINEERING COLLEGE


CS8261 - C PROGRAMMING LABORATORY
while(p1<p2)
result[i++]=*p1++;
result[i]='\0';
strcat(result,replace);
i+=strlen(replace);
p1+=strlen(find);
}
else
{
while(*p1!='\0')
result[i++]=*p1++;
result[i]='\0';
}
}

printf("\nstring after replacement:\n%s",result);


return 0;
}

OUTPUT
Enter the paragraph:
she sells sea shells in the sea shore
Enter the text to find:
sea
Enter the text to replace:
ocean

string after replacement:


she sells ocean shells in the ocean shore

RESULT:

PANIMALAR ENGINEERING COLLEGE


CS8261 - C PROGRAMMING LABORATORY
EX.NO : 12
DATE : 25.06.2021

SOLVE TOWERS OF HANOI USING RECURSION

PROGRAM
#include<stdio.h>
#include<ctype.h>
#include<string.h>
void hanoi(int disks,char source,char auxiliary,char target)
{
if(disks==1)
{
printf("\nMove disk 1 from rod %c to rod %c",source,target);
return;
}

hanoi(disks - 1, source, target, auxiliary);


printf("\nMove disk %3d from rod %c to rod %c",disks,source,target);
hanoi(disks - 1, auxiliary, source, target);
}

int main()
{
int ndisks;
printf("Input how many number of disks?\n");
scanf("%d",&ndisks);
hanoi(ndisks, 'A', 'B', 'C');
return 0;
}

OUTPUT
Input how many number of disks?
3
Move disk 1 from rod A to rod C
Move disk 2 from rod A to rod B
Move disk 1 from rod C to rod B
Move disk 3 from rod A to rod C
Move disk 1 from rod B to rod A
Move disk 2 from rod B to rod C
Move disk 1 from rod A to rod C

RESULT:

PANIMALAR ENGINEERING COLLEGE


CS8261 - C PROGRAMMING LABORATORY
EX.NO : 13
DATE : 25.06.2021

SORT THE LIST OF NUMBERS USING PASS BY REFERENCE

PROGRAM
#include<stdio.h>
void sortNumbers(int a[],int n)
{
int i,j,temp;
for(i=0;i<n-1;i++)
for(j=i+1;j<n;j++)
if( a[i] > a[j] )
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
int main()
{
int i,arr[50],n;
printf("How many number you want to read:\n");
scanf("%d",&n);
printf("Enter %d numbers to sort:\n",n);
for(i=0;i<n;i++)
scanf("%d",&arr[i]);
sortNumbers(arr,n);
printf("numbers after sorting:\n");
for(i=0;i<n;i++)
printf("%-8d",arr[i]);
return 0;
}

OUTPUT
How many number you want to read:
7
Enter 7 numbers to sort:
32 3 65 93 71 12 1
numbers after sorting:
1 3 12 32 65 71 93

RESULT:

PANIMALAR ENGINEERING COLLEGE


CS8261 - C PROGRAMMING LABORATORY
EX.NO : 14
DATE : 26.06.2021

GENERATE SALARY SLIP OF EMPLOYEES USING STRUCTURES AND


POINTERS

PROGRAM
#include<stdio.h>
typedef struct
{
char ename[30],desig[30];
float basic;
} Employee;

int main()
{
int n,i;
float pf,hra,da,gross,tax,net;
Employee *ptr;
printf("\nEnter How many Employees?\n");
scanf("%d",&n);
ptr=(Employee*) malloc( sizeof(Employee) * n );
for(i=0;i<n;i++)
{
printf("Enter Information of Employee %d:\n",i+1);
printf("Name : ");
fflush(stdin);
gets((ptr+i)->ename);
printf("Designation: ");
fflush(stdin);
gets((ptr+i)->desig);
printf("Basic Pay :");
scanf("%f",&(ptr+i)->basic);
}

printf("\n=====================================================");
printf("\nName Designation Basic DA HRA Gross PF Tax NetPay");
printf("\n=====================================================");

for(i=0;i<n;i++)
{
pf = (15/100.0) * (ptr+i)->basic;
da = (38/100.0) * (ptr+i)->basic;
tax = (15/100.0) * (ptr+i)->basic;
hra = (10/100.0) * (ptr+i)->basic;

PANIMALAR ENGINEERING COLLEGE


CS8261 - C PROGRAMMING LABORATORY
gross = (ptr+i)->basic + da + hra;
net = gross - ( pf + tax );
printf("\n%-11s %-11s %7.0f ",(ptr+i)->ename,(ptr+i)->desig,(ptr+i)->basic);
printf("%6.0f %6.0f %8.0f ",da,hra,gross);
printf("%6.0f %6.0f %8.0f ",pf,tax,net);
}
printf("\n=====================================================");
return 0;
}

OUTPUT
Enter How many Employees?
3
Enter Information of Employee 1:
Name : Lakshmi
Designation: Professor
Basic Pay : 76000
Enter Information of Employee 2:
Name : Radha
Designation: Assoc Professor
Basic Pay : 45000
Enter Information of Employee 3:
Name : Sudha
Designation: Asst Professor
Basic Pay : 34000

=================================================================
Name Designation Basic DA HRA Gross PF Tax NetPay
=================================================================
Lakshmi Professor 76000 28880 7600 112480 11400 11400 89680
Radha Assoc Professor 45000 17100 4500 66600 6750 6750 53100
Sudha Asst Professor 34000 12920 3400 50320 5100 5100 40120
=================================================================

RESULT:

PANIMALAR ENGINEERING COLLEGE


CS8261 - C PROGRAMMING LABORATORY
EX.NO : 15
DATE : 26.06.2021

COMPUTE INTERNAL MARKS OF STUDENTS FOR FIVE DIFFERENT


SUBJECTS USING STRUCTURES AND FUNCTIONS

PROGRAM
#include<stdio.h>
#include<math.h>

typedef struct
{
char regno[15],sname[30];
int subjects[5][4];
int internals[5];
} Student;

char subjectcode[5][7]={"HS8151","MA8151","PH8151","CY8151","GE8151"};

void ComputeInternals(Student st[],int n)


{
int i,j,k;
for(i=0;i<n;i++)
{

printf("\n====================================================");
printf("\nRegisterNo :%s Student Name:%s",st[i].regno,st[i].sname);
printf("\n====================================================");
printf("\nInternal marks for 5 subjects(out of 20)");

printf("\n====================================================");
for(j=0;j<5;j++)
{
st[i].internals[j]=0;
for(k=0;k<4;k++)
{
st[i].internals[j] += st[i].subjects[j][k];
}
st[i].internals[j] = round(st[i].internals[j]/400.0*20);
printf("\n%s : %3d",subjectcode[j],st[i].internals[j]);
}
printf("\n=================================================\n\n");
}
}
int main()

PANIMALAR ENGINEERING COLLEGE


CS8261 - C PROGRAMMING LABORATORY
{
Student stlist[]={
{"211420104001","Arthi.S",{{56,76,71,71},
{88,86,89,100},
{90,88,53,99},
{98,89,76,95},
{69,92,74,100}}},
{"211420104002","Barathi.K",{{78,67,87,100},
{99,100,98,100},
{90,88,53,100},
{98,89,76,99},
{69,92,74,85}}}
};
ComputeInternals(stlist,2);
return 0;
}

OUTPUT
RegisterNo :211420104001 Student Name:Arthi.S
=====================================================
Internal marks for 5 subjects(out of 20)
=====================================================
HS8151 : 14
MA8151 : 18
PH8151 : 17
CY8151 : 18
GE8151 : 17
=====================================================
RegisterNo :211420104002 Student Name:Barathi.K
=====================================================
Internal marks for 5 subjects(out of 20)
=====================================================
HS8151 : 17
MA8151 : 20
PH8151 : 17
CY8151 : 18
GE8151 : 16
=====================================================

RESULT:

PANIMALAR ENGINEERING COLLEGE


CS8261 - C PROGRAMMING LABORATORY
EX.NO : 16
DATE : 02.07.2021

INSERT, UPDATE, DELETE AND APPEND TELEPHONE DETAILS OF AN


INDIVIDUAL OR A COMPANY INTO A TELEPHONE DIRECTORY USING
RANDOM ACCESS FILE
PROGRAM
#include<stdio.h>
#include<stdlib.h>
typedef struct
{
char name[15];
char telno[15];
}Telephone;

Telephone a;
FILE *fp,*fp2;
char name[15];
void add()
{
fp=fopen("tele.dat","a");
printf("\n\tName : ");
fflush(stdin);
gets(a.name);
printf("\n\tTelephone No : ");
fflush(stdin);
gets(a.telno);
fwrite(&a,sizeof(Telephone),1,fp);
printf("\n\tRecord added successfully ");
fclose(fp);
}

void update()
{
int found=0;
fp=fopen("tele.dat","r+");
printf("\n\tEnter the Name to update phone : ");
fflush(stdin);
gets(name);
while(!feof(fp))
{
fread(&a,sizeof(Telephone),1,fp);
if(strcmpi(name,a.name)==0)
{
printf("\n\tEnter new Telephone No : ");

PANIMALAR ENGINEERING COLLEGE


CS8261 - C PROGRAMMING LABORATORY
fflush(stdin);
gets(a.telno);
fseek(fp,-1L * sizeof(Telephone),SEEK_CUR);
fwrite(&a,sizeof(Telephone),1,fp);
printf("\n\trecord updated successfully...");
found=1;
break;
}
}
if(!found)
printf("\n\trecord not found for %s",name);
fclose(fp);
}

void deletePhone()
{
int found=0;
fp=fopen("tele.dat","r");
fp2=fopen("copy.dat","w");
printf("\n\tEnter the Name to delete record : ");
fflush(stdin);
gets(name);
while(!feof(fp))
{
strcpy(a.telno," ");
fread(&a,sizeof(Telephone),1,fp);
if(strcmp(a.telno," ")==0)
break;
if(strcmpi(name,a.name)==0)
found=1;
else
fwrite(&a,sizeof(Telephone),1,fp2);
}
if(found==1)
printf("\n\trecord deleted successfully");
else
printf("\n\trecord not found for %s",name);
fclose(fp);
fclose(fp2);
remove("tele.dat");
rename("copy.dat","tele.dat");
}

void display()
{
PANIMALAR ENGINEERING COLLEGE
CS8261 - C PROGRAMMING LABORATORY
fp=fopen("tele.dat","r");
printf("\n\tTelephone Directory");
printf("\n\t================================================");
printf("\n\tName \t\t Telephone No");
printf("\n\t================================================");
while(!feof(fp))
{
strcpy(a.telno," ");
fread(&a,sizeof(Telephone),1,fp);
if(strcmp(a.telno," ")!=0)
printf("\n\t%-15s\t%-15s",a.name,a.telno);
}
printf("\n\t================================================");
fclose(fp);
}

int main()
{
int opt;
A1:
printf("\n\t Telephone Directory");
printf("\n\t==============================");
printf("\n\t1.Add record");
printf("\n\t2.Update record");
printf("\n\t3.Delete record");
printf("\n\t4.Display record");
printf("\n\t5.Exit");
printf("\n\t==-===========================");
printf("\n\tYour option: ");
scanf("%d",&opt);
switch(opt)
{
case 1: add();
break;
case 2: update();
break;
case 3: deletePhone();
break;
case 4: display();
break;
}
if(opt!=5) goto A1;
return 0;
}

PANIMALAR ENGINEERING COLLEGE


CS8261 - C PROGRAMMING LABORATORY
OUTPUT
Telephone Directory
==============================
1.Add record
2.Update record
3.Delete record
4.Display record
5.Exit
==============================
Your option: 1
Name : Ram Kumar
Telephone No : 4343434343

Record added successfully

Your option: 1
Name : Krishnan
Telephone No : 1212121212

Record added successfully

Your option: 2
Enter the Name to update phone : Ram Kumar
Enter new Telephone No : 9000888877

record updated successfully...

Your option: 4
Telephone Directory
=====================================================
Name Telephone No
=====================================================
Ram Kumar 9000888877
Krishnan 1212121212
=====================================================

Your option: 3
Enter the Name to delete record : Ram Kumar

record deleted successfully

RESULT:

PANIMALAR ENGINEERING COLLEGE


CS8261 - C PROGRAMMING LABORATORY
EX.NO : 17
DATE : 03.07.2021

COUNT THE NUMBER OF ACCOUNT HOLDERS WHOSE BALANCE IS


LESS THAN THE MINIMUM BALANCE USING SEQUENTIAL ACCESS
FILE
PROGRAM
#include<stdio.h>
typedef struct
{
char accno[15],name[15];
float balance;
}BankAccount;

BankAccount a;
int main()
{
FILE *fp;
int n,i, count=0;
float minimumBalance=1000;
fp=fopen("bank.dat","w");
printf("\nHow many account details would you like to add?\n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\nEnter account holder %d informations:\n",i+1);
printf("Account Number? ");
fflush(stdin);
gets(a.accno);
printf("Name? ");
fflush(stdin);
gets(a.name);
printf("Initial Balance? ");
scanf("%f",&a.balance);
fwrite(&a,sizeof(a),1,fp);
}

fclose(fp);
fp=fopen("bank.dat","r");
printf("\n=================================================");
printf("\nAccount Number\tAccount Holder Name\tBalance");
printf("\n=================================================");
while(!feof(fp))
{
strcpy(a.accno," ");

PANIMALAR ENGINEERING COLLEGE


CS8261 - C PROGRAMMING LABORATORY
fread(&a,sizeof(a),1,fp);

if(strcmp(a.accno," ")!=0)
{
printf("\n%-15s\t%-20s\t%10.2f",a.accno,a.name,a.balance);
if(a.balance < minimumBalance)
count++;
}
}
printf("\n===================================================");
fclose(fp);
printf("\nNumber of account holder having less than minimum balance is %d",count);
return 0;
}

OUTPUT
How many account details would you like to add?
3
Enter account holder 1 informations:
Account Number? 12612
Name? Kajendran
Initial Balance? 5000
Enter account holder 2 informations:
Account Number? 12613
Name? Rajendran
Initial Balance? 930
Enter account holder 3 informations:
Account Number? 12614
Name? Jeyachendran
Initial Balance? 600
==========================================================
Account Number Account Holder Name Balance
==========================================================
12612 Kajendran 5000.00
12613 Rajendran 930.00
12614 Jeyachendran 600.00
==========================================================
Number of account holder having less than minimum balance is 2

RESULT:

PANIMALAR ENGINEERING COLLEGE

You might also like