0% found this document useful (0 votes)
5 views35 pages

C Lab Manual

Uploaded by

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

C Lab Manual

Uploaded by

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

PROGRAMMING IN C LAB

LAB MANUAL
Ex NO.1 QUADRATIC EQUATION

AIM:

To develop a C program to find the roots of the quadratic equation.

PROCEDURE:

STEP 1: Start the program.


STEP 2: Read the values of a,b,c,d,e,f1,f2,f3,f4,,
STEP 3: To calculate the d<-b2-4ac
STEP 4: To assisn the value of 20
STEP 5: Check if (d==0)
i) If “TRUE” go to step 6
ii) If “FALSE” go to step 8
STEP 6: Write the roots are real and equal
STEP 7: f3(-b+sqrt(d)/x)
STEP 8: f4(-b-sqrt(d)/x)
STEP 9: Write the roots are real and unequal
STEP 10:Write the roots are imaginary.
STEP 11:Stop the program.

/*Quadratic equation*/

#include <stdio.h>
#include <math.h>
main()
{
float a,b,c,d,r1,r2;
clrscr();
printf("Enter a,b,c values");
scanf("%f%f%f",&a,&b,&c);
d=(b*b)-(4*a*c);
if(d==0)
{
r1=-b/(2*a);
r2=r1;
printf("Roots are real and equal\n");
printf("Root1=%f\troot2=%f",r1,r2);
}
else if(d<0)
{
r1=-b/(2*a);
r2=sqrt(-d)/(2*a);
printf("Roots are real and imaginary\n");
printf("Root1=%f\tRoot2=%f",r1,r2);
}
else
{
r1=(-b+sqrt(d))/(2*a);
r2=(-b-sqrt(d))/(2*a);
printf("Roots are real and unequal\n");
printf("Root1=%f\tRoot2=%f",r1,r2);
}
getch();
}

Output

Enter a,b,c values


1
5
6
Roots are real and unequal

Root1=-2.000000 Root2=-3.000000

Enter a,b,c values


1
4
4
Roots are real and equal

Root1=-2.000000 Root2=-2.000000

Enter a,b,c values


2
1
6
Roots are real and imaginary

Root1=-0.250000 Root2=1.713914

RESULT:

Thus the Program is executed and the roots of the Quadratic Equation are
obtained.
Ex NO.2(c) EXPONENT SERIES

AIM:

To develop a C program for exponent series.

PROCEDURE:

STEP 1: Start the program.


STEP 2: Declare is as integral and x1+ sum of float.
STEP 3: Read the value of x and n.
STEP 4: Assign the value of x to t and sum to 1.
STEP 5: Write the value Sum and library.
STEP 6: Stop the progra

/*Exponential form*/

#include<stdio.h>
#include<math.h>
main()
{
float s=1.0;
int i,j,f,x,n;
clrscr();
printf("Enter x and n values");
scanf("%d%d",&x,&n);
for(i=1;i<=n;i++)
{
f=1;
for(j=1;j<=i;j++)
{
f=f*j;
}
s=s+pow(x,i)/f;
}
printf("Exp(x)= %f",s);
getch();
}

OUTPUT :
Enter x and n values
2
3
Exp(x)= 6.333333

RESULT:

Thus the summation of Exponent Series is developed by using C program.

Ex NO.2(a) SINE OF SERIES

AIM:

To develop a C program to find the roots of SINE of SERIES.

PROCEDURE:

STEP 1: Start the program


STEP 2: Read the value of x and n.
STEP 3: In for loop find the value of t and (cos (x)).
STEP 4: Assign the value of x to t and sum to 1.
STEP 5: Write the library for cos(x) and library value..
STEP 6: S

/*Sin(x)=x/1!-x^3/3!+x^5/5!....*/

#include<stdio.h>
#include<math.h>
main()
{
float s=0.0;
int i,j,f,x,n,t=1;
clrscr();
printf("Enter x and n values");
scanf("%d%d",&x,&n);
for(i=1;i<=n;i=i+2)
{
f=1;
for(j=1;j<=i;j++)
{
f=f*j;
}
s=s+t*pow(x,i)/f;
t=-t;
}
printf("Sin(x)=%f",s);
getch();
}

OUTPUT:

Enter x and n values


2
5

sin(x)= 0.933333

RESULT:

Thus the Summation of Sine series was developed by using C program.

Ex NO.2(b) COSINE SERIES

AIM:
To develop a C program to find the roots of COSINE SERIES.

PROCEDURE:

STEP 1: Start the program


STEP 2: Read the value of x and n.
STEP 3: In for loop find the value of t and (cos (x)).
STEP 4: Assign the value of x to t and sum to 1.
STEP 5: Write the library for cos(x) and library value..
STEP 6: Stop the program.

/*cosx=1-x^2/2!+x^4/4!...*/

#include<stdio.h>
#include<math.h>
main()
{
float s=1.0;
int i,j,x,n,f,t=-1;
clrscr();
printf("Enter x and n values");
scanf("%d%d",&x,&n);
for(i=2;i<=n;i=i+2)
{
f=1;
for(j=1;j<=i;j++)
{
f=f*j;
}
s=s+t*pow(x,i)/f;
t=-t;
}
printf("Cos(x)=%f",s);
getch();
}

OUTPUT:

Enter x and n values


2
4

Cos(x)= -0.333333

RESULT:

Thus the summation os cosine series was developed by using C program.

Ex NO.3 ASCENDING AND DESCENDING ORDER


AIM:

To write a C program for arranging marks of the student in ascending and


descending order and also to find lowest and highest mark of the student.

PROCEDURE:

STEP 1: Start the program


STEP 2: Read the value of n
STEP 3: In for loop, read the value of a[i] and assign a[i] to b[i]
STEP 4: In for loop, check whether [i]>a[i] and assign a[i] to total.
STEP 5: In for loop, write the value of a[i], b[i].
STEP 6: Assign a[i] to large and small
STEP 7: In for loop check whether a[i] large true assign a[i] to large.
STEP 8: Write the value of large and small
STEP 9: Stop

PROGRAM:
#include <stdio.h>
int main() {
int n, data[100], i, j, temp;

/* get the number of entries */


printf("Enter your input for n:");
scanf("%d", &n);

/* get the input data */


for (i = 0; i < n; i++)
scanf("%d", &data[i]);

/* sort the given data in ascending order */


for (i = 0; i < n-1; i++) {
for (j = i + 1; j < n; j++) {
if (data[i] > data[j]) {
temp = data[i];
data[i] = data[j];
data[j] = temp;
}
}
}

/* data in ascending order */


printf("Ascending Order:\n");
for (i = 0; i < n; i++)
printf("%d\n", data[i]);

/* data in descending order */


printf("\nDescending Order:\n");
for (i = n-1; i >= 0; i--)
printf("%d\n", data[i]);

return 0;
}

OUTPUT:
Enter the no. of values 4

Enter the values:


56
45
98
78

ASCENDING ORDER: 45 56 78 98
Enter the values:
56
45
98
78

DESCENDING ORDER: 98 78 56 45

RESULT:

Thus the marks are arranged in Ascending and Descending order and also the
lowest and highest marks are obtained.

s
Ex NO.4 ALPHABETICAL ORDER

AIM:
To write a C program for arranging the names in Alphabetical order.

PROCEDURE:

STEP 1: Start the program


STEP 3: Read the n number of names in array using for loop
STEP 4: Copy the value a[i] and b[i] using string function
STEP 5: Compare the value of a[i] to b[i] using string function
STEP 6: Print the alphabetical order the given “n” number of names.
STEP 2: Read the value of n.
STEP 7: Stop the program.

/** ALPHABETICAL ORDER**/

#include<stdio.h>
#include<string.h>
int main(){
int i,j,count;
char str[25][25],temp[25];
puts("How many strings u are going to enter?: ");
scanf("%d",&count);

puts("Enter Strings one by one: ");


for(i=0;i<=count;i++)
gets(str[i]);
for(i=0;i<=count;i++)
for(j=i+1;j<=count;j++){
if(strcmp(str[i],str[j])>0){
strcpy(temp,str[i]);
strcpy(str[i],str[j]);
strcpy(str[j],temp);
}
}
printf("Order of Sorted Strings:");
for(i=0;i<=count;i++)
puts(str[i]);

return 0;
}

OUTPUT:

How many strings u are going to enter:


5

Enter the strings one by one:


BABU
SOMU
NIJAM
AZAAR
KABILAN

Order of sorted things:


AZAAR
BABU
KABILAN
NIJAM
SOMU

RESULT:

Thus the program is executed and the names are arranged in Alphabetical order.

Ex NO.5 FIBONACCI SERIES

AIM:

To write a C program to find the Fibonacci series of given number using


recursion.

PROCEDURE:

STEP 1: Start the program.


STEP 2: Read the value of n.
STEP 3: Calculate the Fibonacci series of given number and using the function fib().
STEP 4: Check whether the value of (n==0)
STEP 5: Write the Fibonacci series
STEP 6: Stop the program.

/*pgm to generate fibonacci series*/


#include<stdio.h>
main()
{
int f1=-1,f2=1,fn;
clrscr();
printf("\nenter the end value of the series:");
scanf("%d",&fn);
printf("\nFIBBONACCI SERIES\n");
fib(f1,f2,fn);
getch();
}

fib(int x,int y,int z)


{
int f3;
f3=x+y;
if(f3<=z)
{
printf("%d\t",f3);
fib(y,f3,z);
}
}

Output

enter the end value of the series: 15

FIBBONACCI SERIES

0 1 1 2 3 5 8 13

RESULT:

Thus the Fibonacci Series using Recursion was executed and the was obtained.

Ex NO.6 FACTORIAL SERIES


AIM:

To write a C program to find the Faxtorial or given number using recursion.

PROCEDURE:

STEP 1: Start the program.


STEP 2: Read the value of n.
STEP 3: Check the whether n < 0
i) If “true” then printed factorial cannot be found.
ii) If”false” then go to next step.
STEP 4: Check if (n==0)
i) if “true” return(0)
ii) if “false” check if (n=!1)
iii) If “true” return (1)
iv) If “false” return(n*fact(n-1)) .
STEP 5: Write the factorial value
STEP 6: Stop the program.

/* Factorial*/
#include<stdio.h>
#include<math.h>
main()
{
int n,f;
clrscr();
printf("\nEnter the value of n:");
scanf("%d",&n);
f=fact(n);
printf("\nfactorial value for %d=%d",n,f);
getch();
}

fact(int n)
{
if(n==1)
{
return(1);
}
else
{
return(n*fact(n-1));
}
}

Output

Enter the value of n:5

factorial value for 5=120

RESULT:

Thus the Factorial of given number was obtained and result verified.

Ex NO.7 MATRIX MANIPULATION


AIM:

To write a C program to perform Matrix Addition, Subtraction, Multiplicaton


using function.

PROCEDURE:

STEP 1: Start the program.


STEP 2: Read the A and B matrix.
STEP 3: Read the element of A and B matrix using Matrix Read()
STEP 4: Write the element A and B Matrices in matrix format using Matrix print().
STEP 5: Read the choice in
i) Addition
ii) Subtraction
iii) Multiplication
iv) Exit
STEP 6: i) When ch==1, check the possibilities and Add A and B matrices and store the
result in C using Matrix Additon() otherwise, Write “matrix Addition is not possible”
ii) When ch==2, check the possibilities and Sub A and B matrices and store the
result in C using Matrix Subtraction () otherwise, Write “matrix Subtraction is
not possible
iii) When ch==3, check the possibilities and Multiplication A and B matrices and
store the result in C using Matrix Multiplication () otherwise, Write “matrix
Multiplication is not possible

STEP 7: Stop the program

/*pgm for matrix manipulation*/

#include<stdio.h>
#include<math.h>
main()
{
int i,j,r,r1,c1,c,a[5][5],b[5][5],c2[5][5];
clrscr();
printf("\n Enter the no. of rows and columns of 1st matrix:");
scanf("%d%d",&r,&c);
printf("\nEnter a matrix");
for(i=1;i<=r;i++)
for(j=1;j<=c;j++)
scanf("%d",&a[i][j]);
printf("\nEnter the no. of rows and columns of 2nd matrix:");
scanf("%d%d",&r1,&c1);
printf("\nEnter b matrix");
for(i=1;i<=r1;i++)
for(j=1;j<=r1;j++)
scanf("%d",&b[i][j]);
clrscr();
printf("\nGiven a matrix\n\n");
for(i=1;i<=r;i++)
{
for(j=1;j<=c;j++)
{
printf("%d\t",a[i][j]);
}
printf("\n");
}
printf("\nGiven b matrix:\n");
for(i=1;i<=r1;i++)
{
for(j=1;j<=c1;j++)
{
printf("%d\t",b[i][j]);
}
printf("\n");
}
printf("\nMatrix addition &multiplication\n");
add(a,b,c2,r,c,r1,c1);
mul(a,b,c2,r,c,r1,c1);
}

add(m1,m2,m3,row,col,row1,col1)
int m1[5][5],m2[5][5],m3[5][5],row,col,row1,col1;
{
int i,j;
if((row==row1)&&(col==col1))
{
printf("\nAddition of two matrices\n");
for(i=1;i<=row;i++)
{
for(j=1;j<=col;j++)
{m3[i][j]=m1[i][j]+m2[i][j];
printf("%d\t",m3[i][j]);
}
printf("\n");
}
}
else
{printf("\nAddition cannot be performed");
}
getch();
}

mul(m1,m2,m3,row,col,row1,col1)
int m1[5][5],m2[5][5],m3[5][5],row,col,row1,col1;
{
int i,j,k;
if(col==row1)
{
printf("\nMultiplication of two matrices\n");
for(i=1;i<=row;i++)
{
for(j=1;j<=col1;j++)
{m3[i][j]=0;
for(k=1;k<=row1;k++)
m3[i][j]=m3[i][j]+m1[i][k]*m2[k][j];
printf("%d\t",m3[i][j]);
}
printf("\n");
}
getch();
}
else
{
printf("\n Multiplication cant be performed");
}
}

Output
Enter the no. of rows and columns of 1st matrix:
2
2

Enter a matrix
1
2
3
4

Enter the no. of rows and columns of 2nd matrix:


2
2

Enter b matrix
4
3
2
1

Given a matrix

1 2
3 4

Given b matrix:
4 3
2 1

Matrix addition &multiplication

Addition of two matrices


5 5
5 5

Multiplication of two matrices


8 5
20 13

RESULT:
Thus matrix Add, Sub and Mul is performed using C function.

EX NO 8 STRING LENGTH

AIM:
To find the length of the string using function pointer.

PROCEDURE:

STEP 1: Start the program


STEP 2: Read the String.
STEP 3: Call the string length().
STEP 4: Check whether the string function is not equal to multiplication.
i) If “true” increment the value I and source.
ii) If “false” then return the length of the string.
STEP 5: Print the length of the string.
STEP 6: Stop the program.

/*pgm for string length*/

#include<stdio.h>
#include<alloc.h>
#include<string.h>
main()
{
int i,ch,l,w;
char res,*s,*s1;
s=malloc(sizeof(char)*200);
s1=malloc(sizeof(char)*200);
ch=0;
while(ch!=6)
{
clrscr();
printf("\t\t\tstring length\n");
printf("\t\t\t*******************\n\n");
printf("select your choice\n");
printf("1.string length\n");
printf("2.string compare\n");
printf("3.string copy\n");
printf("4.counting words\n");
printf("5.palindrome checking\n");
printf("6.exit\n");
printf("enter your choice\n");
scanf("%d",&ch);
switch(ch)
{
case 1:
flushall();
printf("Enter the string\n");
scanf("%[^\n]",s);
i=0;l=0;
while(*(s+i)!='\0')
{
l++;
i++;
}
printf("The length of the string is=%d\n",l);
break;
case 2:
printf("Enter the string:\n");
scanf("%s",s);
printf("Enter the next string\n");
scanf("%s",s1);
for(i=0;i<strlen(s);i++)
if(*(s+i)!=*(s1+i))
{
printf("The two strings are unequal\n");
goto f1;
}
printf("The strings are equal\n");
f1:break;
case 3:
printf("Enter the string:\n");
scanf("%s",s1);
for(i=0;i<=strlen(s1);i++)
*(s+i)=*(s1+i);
printf("The resultant string is:%s\n",s);
break;
case 4:
flushall();
printf("Enter the string\n");
scanf("%[^\n]",s);
w=1;i=1;
while(s[i]!='\0')
{if(*(s+i)==' '||*(s+i)=='\0')
++w;
i++;
}
printf("No. of words are%d\n",w);
printf("No. of characters are %d\n",i);
break;
case 5:
res='f';
printf("Enter the string\n");
scanf("%s",s);
for(i=0;i<=strlen(s)/2;i++)
{if(*(s+i)!=*(s+strlen(s)-1-i))
{res='t';
}
}
if(res=='t')
printf("%s is not a palindrome\n",s);
else
printf("%s is a palindrome\n",s);
break;
case 6:
break;
default:
printf("invalid choice\n");
}
printf("\n press any key to continue...\n");
getch();
}
}

OUTPUT:

string manipulation
*******************

select your choice


1.string length
2.string compare
3.string copy
4.counting words
5.palindrome checking
6.exit
Enter your choice : 1
Enter the string : computer
The length of the string is=8

press any key to continue...


string manipulation
*******************

select your choice


1.string length
2.string compare
3.string copy
4.counting words
5.palindrome checking
6.exit
Enter your choice : 2
Enter the string : computer
Enter the next string : science
The two strings are unequal

press any key to continue...

string manipulation
*******************

select your choice


1.string length
2.string compare
3.string copy
4.counting words
5.palindrome checking
6.exit
Enter your choice : 3
Enter the string: computer
The resultant string is:computer

press any key to continue...


string manipulation
*******************

select your choice


1.string length
2.string compare
3.string copy
4.counting words
5.palindrome checking
6.exit
Enter your choice : 4
Enter the string: computer science
No. of words are : 2
No. of characters in the line : 16

press any key to continue...


string manipulation
*******************
select your choice
1.string length
2.string compare
3.string copy
4.counting words
5.palindrome checking
6.exit
Enter your choice : 5
Enter the string: malayalam
Malayalam is a palindrome

press any key to continue...


string manipulation
*******************

select your choice


1.string length
2.string compare
3.string copy
4.counting words
5.palindrome checking
6.exit
Enter your choice : 6

press any key to continue...

RESULT:

Thus the length of the given string was found using function pointer.

EX NO 8 MARKLIST CREATION
AIM:

To Develop a C program to implement the marklist using files

PROCEDURE:

STEP 1: Start the program.


STEP 2: Declare the required variable and files and read A
STEP 3: Read the student files in a white mode.
STEP 4: Read the Details of students and complete the total and avg.
STEP 5: Write the details of 2 Students and stud.dat
STEP 6: Close the file.
STEP 7: Open the file student Data in read mode
STEP 8: Read the details of the students from the student data file.
STEP 9: Write the details.
STEP 10: Close the file.
STEP 11: Stop the program.

/*marklist creation*/

#include<stdio.h>
main()
{
struct stud
{
int regno;
char name[25],class[12];
int sub1,sub2,sub3;
}s;
char c;
FILE *crea;
clrscr();
crea=fopen("mark.dat","w");
do
{
printf("Enter your reg.no.:");
scanf("%d",&s.regno);
printf("Enter your name:");
scanf("%s",&s.name);
printf("Enter your class");
scanf("%s",&s.class);
printf("Enter your sub1 mark:\n");
scanf("%d",&s.sub1);
printf("Enter your sub2 mark:\n");
scanf("%d",&s.sub2);
printf("Enter your sub 3 mark:\n");
scanf("%d",&s.sub3);
fprintf(crea,"%10d",s.regno);
fprintf(crea,"%20s",s.name);
fprintf(crea,"%12s",s.class);
fprintf(crea,"%3d",s.sub1);
fprintf(crea,"%3d",s.sub2);
fprintf(crea,"%3d",s.sub3);
printf("\n");
printf("\nDo u want to add another record(y/n):\n");
c=toupper(getch());
if(c!='N')
fprintf(crea,"\n");
}
while(c!='N');
fclose(crea);
}

OUTPUT::

Enter your reg.no.: 102


Enter your name: Ram
Enter your class: bsc
Enter your sub1 mark: 98
Enter your sub2 mark: 56
Enter your sub3 mark: 85

Do u want to add another record(y/n): y

Enter your reg.no.: 103


Enter your name: Kumar
Enter your class: bsc
Enter your sub1 mark: 78
Enter your sub2 mark: 56
Enter your sub 3 mark: 98

Do u want to add another record(y/n):

RESULT:
Thus the marksheet is prepared using files.

EX NO 9 MARKLIST PROCESSING
AIM:

To find the length of the string using function pointer.

PROCEDURE:

STEP 1: Start the program.


STEP 2: Input marks of 3 subjects in some variable sub1, sub2, sub3
STEP 3: Calculate the % using formula percentage = sub1+sub2+sub3+3.0;
i) Carefully notice I have divided some with 3.0, instead of 3 to avoid
integer division.
STEP 4: On the basis of percentage find grade of the student.
STEP 5: Check if(per>=90) then, print”Grade A”
STEP 6: If per is not more than 90, then chwck remaining conditions mentioned and print
grade.
STEP 7 Stop the program.:

/*marklist processing*/

#include<stdio.h>
#include<string.h>
main()
{
struct stud
{
int regno,sub1,sub2,sub3;
char name[25],class[12];
}s;
char c,result[6];
int total;
float avg;
FILE *crea;
clrscr();
crea=fopen("mark.dat","r");
printf("regno\tname\tclass\tsub1\tsub2\tsub3\ttotal\tavg\tresult\t\t\n");
printf("----------------------------------------------------------\n");
while(!feof(crea))
{
fscanf(crea,"%d %s %s %d %d
%d",&s.regno,&s.name,&s.class,&s.sub1,&s.sub2,&s.sub3);
total=s.sub1+s.sub2+s.sub3;
avg=total/3.0;
if((s.sub1>=40)&&(s.sub2>=40)&&(s.sub3>=40))
strcpy(result,"pass");
else
strcpy(result,"fail");
printf("%d\t %s\t %s\t %d\t %d\t %d\t %d\t %f\t %s",s.regno,s.name,s.class,
s.sub1,s.sub2,s.sub3,total,avg,result);
printf("\n");
}
fclose(crea);
}

Output

regno name class sub1 sub2 sub3 total avg result


----------------------------------------------------------------------------------------------
102 Ram bsc 98 56 85 239 79.666664 pass
103 Kumar bsc 78 56 98 232 77.333336 pass

RESULT:

Thus the marksheet is prepared using files

EX NO 10 PAYROLL PREPARATION
AIM:

To develop a C program for implementing payroll using files.

PROCEDURE:

STEP 1: Start the program


STEP 2: Declare the variables.
STEP 3: Read the choice.
STEP 4: Open the file emp.dat in write mode.
STEP 5: Read the details to the file exp.file.
STEP 6: Close the file emp.dat in read mode.
STEP 7: Open the file emp.dat in read mode.
STEP 8: Read the details using array emp from emp.dat.
STEP 9: Swap the details using array.
STEP 10:Close the file program in c
STEP 11: Compile matpayallowance selection.
STEP 12: Stop the program.

/**PAYROLL PREPARATION**/

#include<stdio.h>

struct Employee
{
int Num;
char name[50];
float salary;
};

int main()
{
struct Employee Emp;
FILE *fp;
int x,i,hra,da,cca,fpay;
printf("Enter the Number of Employees\n");
scanf("%d",&x);
fp = fopen("abc.txt","w");
fflush(stdin);
for(i=1;i<=x;i++)
{
printf("\nEnter Employee Number.\n");
scanf("%d",&Emp.Num);
printf("Enter Employee Name.\n");
scanf("%s",&Emp.name);
printf("Enter Employee Salary.\n");
scanf("%f",&Emp.salary);
fwrite(&Emp,sizeof(Emp),1,fp);
}
fclose(fp);
fp = fopen("abc.txt","r");
for(i=1;i<=x;i++)
{
fread(&Emp, sizeof(Emp),1,fp);
printf("\nEmployee Details\nNumber : %d\nName : %s\nSalary : %f\
n",Emp.Num,Emp.name,Emp.salary);
hra = 0.15*(Emp.salary);
da = 0.55*(Emp.salary);
cca = 0.05*(Emp.salary);
fpay = Emp.salary + hra + da + cca;
printf("HRA : %d\nDA : %d\nCCA : %d\nFinal Salary : %d\n",hra,da,cca,fpay);
}
fclose(fp);
}

/* Output
Enter the Number of Employees
3

Enter Employee Number.


1
Enter Employee Name.
Deepanshu
Enter Employee Salary.
4500

Enter Employee Number.


2
Enter Employee Name.
Abhilash
Enter Employee Salary.
60000

Enter Employee Number.


3
Enter Employee Name.
Vivek
Enter Employee Salary.
123456

Employee Details
Number : 1
Name : Deepanshu
Salary : 4500.000000
HRA : 674
DA : 2475
CCA : 225
Final Salary : 7874

Employee Details
Number : 2
Name : Abhilash
Salary : 60000.000000
HRA : 8999
DA : 33000
CCA : 3000
Final Salary : 104999

Employee Details
Number : 3
Name : Vivek
Salary : 123456.000000
HRA : 18518
DA : 67900
CCA : 6172
Final Salary : 216046
*/

RESULT:

Thus the Payroll is obtained using files.


EX NO 11 EB BILL PREPARATION

AIM:

To develop a C program for EB bill preparation using files.

PROCEDURE:

STEP 1: Start the program.


STEP 2: Calculate the total electricity bill according to the given condition.
STEP 3: Declare the value of the variables.
STEP 4: Calculate the EB bill using if else in C programming
STEP 5 Similarly check rest of the conditions and calculate total amount.
STEP 6: Program to find the EB Bill using if else.
STEP 7: Stop the program.

/** EB BILL PREPARATION**/

#include <stdio.h>

int main()
{
int unit;
float amt, total_amt, sur_charge;

/* Input unit consumed from user */


printf("Enter total units consumed: ");
scanf("%d", &unit);

/* Calculate electricity bill according to given conditions */


if(unit <= 50)
{
amt = unit * 0.50;
}
else if(unit <= 150)
{
amt = 25 + ((unit-50) * 0.75);
}
else if(unit <= 250)
{
amt = 100 + ((unit-150) * 1.20);
}
else
{
amt = 220 + ((unit-250) * 1.50);
}
/*
* Calculate total electricity bill
* after adding surcharge
*/
sur_charge = amt * 0.20;
total_amt = amt + sur_charge;

printf("Electricity Bill = Rs. %.2f", total_amt);

return 0;
}

OUTPUT:

Enter total units consumed: 150

Electricity Bill – Rs.120.00

RESULT:

Thus the Payroll is obtained using files.

You might also like