Menu
×
Tutorials Ms Word Tutorial Ms Excel Tutorial Ms PowerPoint Tutorial C Language Tutorial C++ Tutorial C Sharp Tutorial Visual Basic Tutorial HTML Tutorial CSS Tutorial JavaScript Tutorial WordPress Tutorial
     ❯   

ADVERTISEMENT

Calculate Gross Salary

This code calculates and displays various components of an employee’s salary, including dearness allowance, house rent allowance, and provident fund deduction. It then calculates the gross salary based on these components and the user-provided basic pay.

#include<stdio.h>
main(){

  float basicPay,dearnessAllowance,houseRentAllowance,grossSalary,providentFund;
  printf("Enter Basic Pay \n");
  scanf("%f",&basicPay);

  houseRentAllowance=0.2*basicPay;
  dearnessAllowance=0.4*basicPay;
  providentFund=0.12*basicPay;
  grossSalary=basicPay+dearnessAllowance+houseRentAllowance+providentFund;

  printf("Basic Pay=%.2f\n",basicPay);
  printf("Dearness Allowance=%.2f\n",dearnessAllowance);
  printf("House Rent Allowance=%.2f\n",houseRentAllowance);
         printf("ProvidentFund=%.2f\n",providentFund);
  printf("Gross Salary=%.2f\n",grossSalary);
}
C Programming Examples

OUTPUT
Enter Basic Pay
15000
Basic Pay=15000.00
Dearness Allowance=6000.00
House Rent Allowance=3000.00
ProvidentFund=1800.00
Gross Salary=25800.00
C Programming Examples

Explanation:

This C program calculates the gross salary of an employee based on their basic pay, dearness allowance (DA), house rent allowance (HRA), and provident fund (PF). Here’s a step-by-step explanation of the code:

Header File:

  • The program includes the standard C library header <stdio.h> for input and output operations.

Main Function:

  • The main function is the entry point of the program.

Variable Declaration:

Five variables are declared:

  • basicPay (float): To store the basic pay of the employee.
  • dearnessAllowance (float): To store the calculated dearness allowance.
  • houseRentAllowance (float): To store the calculated house rent allowance.
  • grossSalary (float): To store the calculated gross salary.
  • providentFund (float): To store the calculated provident fund deduction.

User Input:

The program uses printf and scanf functions to take user input. It prompts the user to enter their basic pay.

  • Allowance and Deduction Calculations:
  • The code calculates various components of the salary as follows:
  • houseRentAllowance is 20% of the basicPay.
  • dearnessAllowance is 40% of the basicPay.
  • providentFund is 12% of the basicPay.

Gross Salary Calculation:

  • The grossSalary is calculated as the sum of basicPay, dearnessAllowance, houseRentAllowance, minus the providentFund.

Output:

  • The program prints the calculated values for each component, including the basic pay, dearness allowance, house rent allowance, provident fund deduction, and the gross salary.
  • Values are displayed with two decimal places using the format specifier %.2f.

End of Program:

  • After printing the results, the program reaches the end of the main function, concluding the program’s execution.
Spread the love
Scroll to Top
Scroll to Top