Introduction:
A C program to prepare pay slip is essential when building small payroll systems or automating salary calculations. This post will help you understand how to calculate the gross and net salary using allowances and deductions like DA, HRA, MA, and PF. By following this example, you’ll improve your skills in using arithmetic operations and formatted output in C.
Problem Description:
You need to develop a C program that takes the basic salary as input and calculates the complete pay slip with detailed components. The calculation rules are:
Component | Formula |
---|---|
DA | 10% of basic salary |
HRA | 7.5% of basic salary |
MA | ₹300 (fixed amount) |
PF | 12.5% of basic salary |
Gross Salary | Basic + DA + HRA + MA |
Net Salary | Gross – PF |
C Program to Prepare Pay Slip
#include <stdio.h>
int main() {
float basic, da, hra, pf, gross, net;
float ma = 300.0;
// Take user input
printf("Enter Basic Salary: ₹");
scanf("%f", &basic);
// Perform calculations
da = 0.10 * basic;
hra = 0.075 * basic;
pf = 0.125 * basic;
gross = basic + da + hra + ma;
net = gross - pf;
// Display formatted pay slip
printf("\n------ PAY SLIP ------\n");
printf("Basic Salary : ₹%.2f\n", basic);
printf("DA (10%%) : ₹%.2f\n", da);
printf("HRA (7.5%%) : ₹%.2f\n", hra);
printf("Medical Allowance: ₹%.2f\n", ma);
printf("PF (12.5%%) : ₹%.2f\n", pf);
printf("Gross Salary : ₹%.2f\n", gross);
printf("Net Salary : ₹%.2f\n", net);
printf("----------------------\n");
return 0;
}
Code Explanation and Flow
Input Handling
The user enters the basic salary, which the program reads using scanf()
.
Salary Components Calculation
The program calculates:
- DA as 10% of basic salary
- HRA as 7.5% of basic salary
- MA is a constant amount of ₹300
- PF as 12.5% of basic salary
All these values are stored in separate variables for easy readability and maintenance.
Gross and Net Salary
Then it adds the allowances to the basic salary to calculate Gross Salary.
Next, it subtracts PF from the gross amount to find the Net Salary.
Output Format
Finally, the program prints a clean and organized pay slip. Each amount is formatted to two decimal places, providing a professional touch.
Use Case and Benefits
This C program to prepare pay slip offers a real-world application of basic C skills. It helps beginners understand how to:
- Apply percentage formulas
- Format financial data
- Structure output in a user-friendly layout
You can easily expand this program to handle multiple employees or add features like tax deductions and bonus calculations.
Conclusion:
This simple C program to prepare pay slip covers all essential elements of salary calculation using variables, constants, and arithmetic expressions. It reinforces foundational skills in C programming, especially for applications in payroll or employee management systems.