C Program to Find the Gross Salary of an Employee

Calculating the gross salary of an employee is a common task in programming exercises. The gross salary is the sum of the basic salary and allowances like Dearness Allowance (DA) and House Rent Allowance (HRA). This tutorial explains how to compute gross salary in C using simple arithmetic operations.

Why Learn Gross Salary Calculation?

Calculating gross salary helps beginners understand arithmetic operations, user input, and variables in C. It is also a practical example of real-world programming where employee payroll computations are automated.

Basic Formula for Gross Salary

Gross Salary = Basic Salary + DA + HRA Where: - **DA** (Dearness Allowance) = 10% of Basic Salary - **HRA** (House Rent Allowance) = 20% of Basic Salary

Program to Find Gross Salary

C
#include <stdio.h>

int main() {
    float basicSalary, da, hra, grossSalary;

    // Input basic salary
    printf("Enter the basic salary of the employee: ");
    scanf("%f", &basicSalary);

    // Calculate allowances
    da = 0.10 * basicSalary;  // 10% DA
    hra = 0.20 * basicSalary;  // 20% HRA

    // Calculate gross salary
    grossSalary = basicSalary + da + hra;

    // Display the result
    printf("Gross Salary of the employee: %.2f", grossSalary);

    return 0;
}
Sample Output:

Enter the basic salary of the employee: 50000
Gross Salary of the employee: 65000.00

Explanation

  • We declare `basicSalary`, `da`, `hra`, and `grossSalary` as float to handle decimal values.
  • The `scanf` function takes input from the user for the basic salary.
  • DA is calculated as 10% of the basic salary.
  • HRA is calculated as 20% of the basic salary.
  • Gross salary is the sum of basic salary, DA, and HRA.
  • Finally, `printf` displays the gross salary up to 2 decimal places.

Tips for Beginners

  • Use float or double data type to handle salaries with decimals.
  • Always ensure input validation for negative or unrealistic salaries.
  • Modify DA and HRA percentages based on company policy.

Practice Exercises

  • Calculate gross salary with additional allowances like medical or travel allowance.
  • Write a program to compute net salary after deductions like tax and provident fund.
  • Create a program to print a salary slip for multiple employees.

Conclusion

Calculating the gross salary of an employee in C is a straightforward example to practice arithmetic operations, user input, and variables. Mastering this exercise provides a foundation for more advanced payroll or finance-related programming tasks.

Note: Note: Start with fixed DA and HRA percentages, then explore dynamic inputs or multiple allowance types to expand the program.