This blog is under construction

Monday, 8 July 2013

C program to calculate Gross and net salary of an employee

Write a C program to calculate Gross and net salary of an employee.

  #include <stdio.h>
  int main() {
        float basic, hra, da, ma, pf, insurance, net, gross;

        /* get the salary inputs from the user */
        printf("Enter your basic salary:");
        scanf("%f", &basic);
        printf("House Rent Allowance: ");
        scanf("%f", &hra);
        printf("Dearness Allowance:");
        scanf("%f", &da);
        printf("Medical Allowance:");
        scanf("%f", &ma);
        printf("Provident Fund and Insurance amount:");
        scanf("%f%f", &pf, &insurance);

        /* gross salary calculation */
        gross = basic + (hra * basic) / 100 + (da * basic) / 100;
        gross = gross + (ma * basic) / 100;

        /* net salary calculation */
        net = gross - (pf + insurance);

        /* print the salary slip */
        printf("\nSalary Slip:\n");
        printf("Basic Salary: %.2f\n", basic);
        printf("House Rent Allowance: %.2f\n", hra);
        printf("Dearness Allowance: %.2f\n", da);
        printf("Medical Allowance: %.2f\n", ma);
        printf("\nGross Salary: %.2f Rupees\n", gross);

        printf("\nDeductions: \n");
        printf("Provident fund: %.2f\n", pf);
        printf("Insurance: %.2f\n", insurance);
        printf("\nNet Salary: %.2f Rupees\n", net);
        return 0;

  jp@jp-VirtualBox:~/$ ./a.out
  Enter your basic salary:8000
  House Rent Allowance: 50
  Dearness Allowance:20
  Medical Allowance:25
  Provident Fund and Insurance amount:1000 1000

  Salary Slip:
  Basic Salary: 8000.00
  House Rent Allowance: 50.00
  Dearness Allowance: 20.00
  Medical Allowance: 25.00

  Gross Salary: 15600.00 Rupees

  Provident fund: 1000.00
  Insurance: 1000.00

  Net Salary: 13600.00 Rupees

See Also:

No comments:

Post a Comment