How to Calculate Gross Salary by C Program

Calculate Gross Salary by C Program

Introduction :

Calculating gross salary is a common task in every sector. Gross salary is the total amount of earnings which an employee receives from his employer. It generally includes the basic salary along with various allowances (HRA and DA). You can create a simple C program that calculates gross salary of an employee. In this article, I shall show you how to calculate the gross salary of an employee in C programming language.

About the program :

This is a simple C program that calculates the gross salary of an employee. Here, you have to input the basic salary, house rent allowance (HRA) and dearness allowance (DA) of the employee. When you run the program, it asks you to enter name of employee, basic salary and percentage of allowance (HRA and DA). Then, it calculates the gross salary and display the result on the console screen.

Explanation of the program :

You have to include stdio.h library in the program. Then, declare a character array like “employee_name” in the main() function. You have to also declare float variables such as “basic”, “hra”, “da” and “gross”. Now, ask the user to enter name, basic salary, HRA, and DA of the employee using printf() function.

You can store the name of the employee in “employee_name” array using the gets() function. Using scanf() function, store the basic salary, HRA and DA in “basic”, “hra” and “da” variables respectively. After that, calculate the gross salary of the employee and display it on the console screen. Here, I use “%.2f” formatted specifier to print two decimal places of the result.

How run the program :

First, create a C file (gross_salary.c) in VS Code and paste the below code in it to run the program. You can see how install VS Code in your PC.

Source code of the program :

The following code is the source code of calculating gross salary in C programming language. You can use the below code in your program to calculate gross salary of an employee.

/*Developed by Puskar Jasu*/
 #include <stdio.h>
int main()
{
	char employee_name[60];
	float basic, hra, da, gross;
	printf("Enter name of the employee\n");
  	gets(employee_name);
	printf("Enter the basic of %s\n",employee_name);
  	scanf("%f", &basic);
	printf("Enter the hra of %s\n",employee_name);
  	scanf("%f", &hra);
	printf("Enter the da of %s\n",employee_name);
  	scanf("%f", &da);  	 	
	gross = basic + basic * (hra/100) + basic * (da/100);
	printf("The gross salary of %s is %.2f\n", employee_name,gross); 	
  	return 0;
}

Output of the program :

After running the program on your PC, you can see the output of the program like below image.

output of calculate gross salary in the C programming language

Conclusion :

At last, you have learned how to calculate gross salary in the C programming language. Thank you for visiting my site.

Scroll to Top