C Program to Prepare Pay Slip with DA, HRA, MA, PF and Net Salary Calculation

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:

ComponentFormula
DA10% of basic salary
HRA7.5% of basic salary
MA₹300 (fixed amount)
PF12.5% of basic salary
Gross SalaryBasic + DA + HRA + MA
Net SalaryGross – 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.

Previous Article

How to Create a C Program to Display Grades Based on Marks (If-Else Ladder)

Next Article

C Program to Print Day of the Week for Numbers 1 to 7

Write a Comment

Leave a Comment

Your email address will not be published. Required fields are marked *

Subscribe to our Newsletter

Subscribe to our email newsletter to get the latest posts delivered right to your email.
Pure inspiration, zero spam ✨