Gross salary calculation program in C

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:

  1. Save the code in a file with a .c extension, such as salary_calculation.c.
  2. Open a terminal or command prompt and navigate to the directory where the file is saved.
  3. Compile the program using a C compiler (e.g., GCC) by running the following command:Copy codegcc -o salary_calculation salary_calculation.c This will create an executable file named salary_calculation.
  4. 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.

Posted in: C