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 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