Here is a C program that calculates an employee's bonus and gross salary based on their basic salary. The purpose of this program is to demonstrate basic mathematical calculations using C.
Example Program:
#include <stdio.h>
void main() {
// Declare variables
float basic_salary, bonus, gross_salary;
// Get basic salary from user
printf("Enter basic salary: ");
scanf("%f", &basic_salary);
// Calculate bonus
if (basic_salary <= 10000) {
bonus = basic_salary * 0.1;
} else {
bonus = basic_salary * 0.2;
}
// Calculate gross salary
gross_salary = basic_salary + bonus;
// Print results
printf("Bonus: %.2f\n", bonus);
printf("Gross salary: %.2f\n", gross_salary);
}
Program Output:
Enter basic salary: 5000
Bonus: 500.00
Gross salary: 5500.00
In the above C program, the basic salary is entered by the user and stored in a variable called basic_salary
. The program then calculates the bonus using an if-else
statement. If the basic salary is less than or equal to 10000
, the bonus is 10%
of the basic salary. Otherwise, the bonus is 20%
of the basic salary.
Finally, the program calculates the gross salary by adding the bonus to the basic salary and prints the results on the screen.
This is a simple example but illustrates the basic concepts of reading input, performing calculations, and printing output in a C program.