DA, HRA, Gross Salary: C Program

Ramesh’s basic salary is input through the keyboard. His dearness allowance is 40% of basic salary, and house rent allowance is 20% of basic salary. Write a program to calculate his gross salary.

Related Read:
C Program to Calculate Gross Salary of an Employee

Basic Salary, DA, HRA, Gross Salary: C Program


[youtube https://www.youtube.com/watch?v=CoEVA_fUU8Q]

YouTube Link: https://www.youtube.com/watch?v=CoEVA_fUU8Q [Watch the Video In Full Screen.]


Source Code: Basic Salary, DA, HRA, Gross Salary: C Program

#include < stdio.h >

int main()
{
    float bs, hra, da, gs;

    printf("Enter basic salary\n");
    scanf("%f", &bs);

    hra = bs * (20/100.00);
    da  = bs * (40/100.00);

    gs  = bs + hra + da;

    printf("Gross Salary = %f\n", gs);

    return 0;
}

Output 1:
Enter basic salary
10000
Gross Salary = 16000.000000

Output 2:
Enter basic salary
20000
Gross Salary = 32000.000000

#include < stdio.h >

int main()
{
    float bs, hra, da, gs;

    printf("Enter basic salary\n");
    scanf("%f", &bs);

    hra = bs * (0.2);
    da  = bs * (0.4);

    gs  = bs + hra + da;

    printf("Gross Salary = %f\n", gs);

    return 0;
}

Output 1:
Enter basic salary
10000
Gross Salary = 16000.000000

Output 2:
Enter basic salary
20000
Gross Salary = 32000.000000

Wrong division, while calculating HRA and DA

#include < stdio.h >

int main()
{
    float bs, hra, da, gs;

    printf("Enter basic salary\n");
    scanf("%f", &bs);

    hra = bs * (20/100);
    da  = bs * (40/100);

    gs  = bs + hra + da;

    printf("Gross Salary = %f\n", gs);

    return 0;
}

Output 1:
Enter basic salary
10000
Gross Salary = 10000.000000

Output 2:
Enter basic salary
20000
Gross Salary = 20000.000000

You can see that the answer is wrong. This is because we are dividing 20 and 40 by an integer number i.e., 100, so it returns only the integer part of the result which is 0. So 0 multiplied by anything will be 0. So HRA and DA will be 0. So basic salary and gross salary will be shown equal in that case, which is wrong result.

Formula to calculate Gross Salary is:
Gross Salary = Basic Salary + Dearness allowance + House Rent Allowance.

For list of all c programming interviews / viva question and answers visit: C Programming Interview / Viva Q&A List

For full C programming language free video tutorial list visit:C Programming: Beginner To Advance To Expert

C Program to Calculate Gross Salary of an Employee

In a company an employee is paid as under: If his basic salary is less than 5000 then he’ll get 10% of his base salary as HRA and 90% of his base salary as DA. If his basic salary is above 5000, then he’ll get 600 HRA and 95% of his base salary as DA.

HRA – House Rent Allowance.
DA – Dearness Allowance.

C Program to Calculate Gross Salary of an Employee


[youtube https://www.youtube.com/watch?v=qqbhNjWedLw]

YouTube Link: https://www.youtube.com/watch?v=qqbhNjWedLw [Watch the Video In Full Screen.]


Source Code: Calculate Gross Salary of an employee

#include < stdio.h >

int main()
{
    float bs, gs, da, hra;

    printf("Enter basic salary\n");
    scanf("%f", &bs);

    if( bs < 5000 )
    {
        hra = bs * 10 / 100;
        da  = bs * 90 / 100;
    }
    else
    {
        hra = 600;
        da  = bs * 95 / 100;
    }

    gs = bs + da + hra;

    printf("Gross Salary is Rs %f\n", gs);

    return 0;
}

Output 1:
Enter basic salary
5500
Gross Salary is Rs 11325.000000

Output 2:
Enter basic salary
4000
Gross Salary is Rs 8000.000000

Formula to calculate Gross Salary is:
Gross Salary = Basic Salary + Dearness allowance + House Rent Allowance.

For full C programming language free video tutorial list visit:C Programming: Beginner To Advance To Expert