Here’s a simple example of a gross salary calculation program in C:
#include <stdio.h>
int main() {
float basicSalary, allowances, bonuses, grossSalary;
// Input basic salary, allowances, and bonuses
printf("Enter basic salary: ");
scanf("%f", &basicSalary);
printf("Enter allowances: ");
scanf("%f", &allowances);
printf("Enter bonuses: ");
scanf("%f", &bonuses);
// Calculate gross salary
grossSalary = basicSalary + allowances + bonuses;
// Display the gross salary
printf("Gross salary: %.2f\n", grossSalary);
return 0;
}
To compile and run the program, follow these steps:
- Save the code in a file with a
.c
extension, such assalary_calculation.c
. - Open a terminal or command prompt and navigate to the directory where the file is saved.
- Compile the program using a C compiler (e.g., GCC) by running the following command:Copy code
gcc -o salary_calculation salary_calculation.c
This will create an executable file namedsalary_calculation
. - Run the program by executing the following command:bashCopy code
./salary_calculation
The program prompts the user to enter the basic salary, allowances, and bonuses. It then calculates the gross salary by summing up the inputs. Finally, it displays the calculated gross salary on the screen.
Feel free to modify and enhance the program as per your specific requirements.