Ques:-6) If his basic salary is less than Rs. 1500, then HRA=10% of basic salary and DA=25% of basic. If his salary is either equal to or above Rs. 1500, then HRA=Rs. 500 and DA=50% of basic. If the employee’s salary is input through the keyboard write a program to find his gross salary.

				
					#include<stdio.h>
#include<conio.h>
void main()
{
   int basic_sal,HRA=0,DA=0,net_sal=0;
   clrscr();
   printf("enter the basic salary:");
   scanf("%d",&basic_sal);
   if(basic_sal<1500)
   {
     HRA=(basic_sal*10)/100;
     DA=(basic_sal*25)/100;
     net_sal=basic_sal-(HRA+DA);
   }
   else
   {
     HRA=500;
     DA=(basic_sal*50)/100;
     net_sal=basic_sal-(HRA+DA);
   }
   printf("\nHRA = %d",HRA);
   printf("\nDA = %d",DA);
   printf("\nnet salary=%d",net_sal);
 getch();
   }

				
			

Out Put

Another Example

				
					#include <stdio.h>

int main() {
    float basic_salary, HRA, DA, gross_salary;

    // Input basic salary from the user
    printf("Enter the basic salary: ");
    scanf("%f", &basic_salary);

    // Calculate HRA and DA based on the conditions
    if (basic_salary < 1500) {
        HRA = 0.10 * basic_salary;
        DA = 0.25 * basic_salary;
    } else {
        HRA = 500;
        DA = 0.50 * basic_salary;
    }

    // Calculate the gross salary
    gross_salary = basic_salary + HRA + DA;

    // Output the gross salary
    printf("The gross salary is: %.2f\n", gross_salary);

    return 0;
}

				
			

Explanation:

  1. Input: The program first prompts the user to enter the basic salary and stores it in the basic_salary variable.
  2. Condition Check:
    • If the basic_salary is less than Rs. 1500, HRA is calculated as 10% of the basic salary, and DA is calculated as 25% of the basic salary.
    • If the basic_salary is Rs. 1500 or more, HRA is set to Rs. 500, and DA is calculated as 50% of the basic salary.
  3. Gross Salary Calculation: The gross salary is then calculated by summing the basic salary, HRA, and DA.
  4. Output: Finally, the program prints the gross salary.

How to Compile and Run:

  1. Save the program to a file, for example, gross_salary.c.
  2. Open a terminal and navigate to the directory containing the file.
  3. Compile the program using a C compiler, such as gcc
				
					gcc -o gross_salary gross_salary.c

				
			

4. Run the compiled program: sh

				
					./gross_salary

				
			

5. Input the basic salary when prompted, and the program will output the gross salary.

Scroll to Top