Practical-28
Write a c program to input employee no, employee name and basic and to store output into empdata file in following format.
------------------------------------------------------------------------------------------
Emp-No Name Basic DA HRA MA PF GROSS NET-PAY
------------------------------------------------------------------------------------------
1 xyz 5000 2500 500 100 500 8100 7600
2
3
-------------------------------------------------------------------------------------------
DA = 50% of Basic HRA =10% of Basic
MA = 100 PF = 10% of Basic
GROSS = BASIC + DA + HRA + MA NET-PAY = GROSS – PF
Introduction
Code
Practical-28.c
#include <stdio.h>
void main()
{
int empNo, basic;
float da, hra, ma, pf, gross, netPay;
char name[30];
// Read the employee number, name, and basic salary
printf("Enter employee number: ");
scanf("%d", &empNo);
printf("Enter name: ");
scanf("%s", name);
printf("Enter basic salary: ");
scanf("%d", &basic);
// Calculate DA, HRA, MA, PF, Gross, and Net Pay
da = basic * 0.5;
hra = basic * 0.1;
ma = 100;
pf = basic * 0.1;
gross = basic + da + hra + ma;
netPay = gross - pf;
// Open the empdata file for writing
FILE *fp = fopen("empdata.txt", "a");
if (fp == NULL)
{
printf("Error opening file!\n");
return 1;
}
// Write the employee data to the file
fprintf(fp, "%d %s %d %.2f %.2f %.2f %.2f %.2f %.2f\n", empNo, name, basic, da, hra, ma, pf, gross, netPay);
// Close the file
fclose(fp);
// Display the result
printf("\nA/c Department\n");
printf("---------------------------------------------------\n");
printf("Emp-No Name Basic DA HRA MA PF GROSS NET-PAY\n");
printf("---------------------------------------------------\n");
printf("%d %s %d %.2f %.2f %.2f %.2f %.2f %.2f\n", empNo, name, basic, da, hra, ma, pf, gross, netPay);
}
Output