C Program for Calculating and Printing Bonus and Gross Salary Based on Basic Salary

In this article, we will learn how to create a program in C that will ask the user to enter his or her basic salary as input and then compute the bonus amount (bonus will be calculated at 20% of the basic salary) and gross salary using the given basic salary of the employee.

int main()
    float basic, bonus, gross;
    printf("Enter basic salary of the Employee: ");
    scanf("%f", &basic);
    bonus = (basic*20)/100;
    gross = bonus + basic;
    printf("\nBonus = %0.2f", bonus);
    printf("\nGross = %0.2f", gross);
    return 0;

As the above program was written in the Code::Blocks IDE, here is the first snapshot of the sample run:

c program calculate bonus salary

Provide the basic salary of the employee, and the program will print the Bonus@20% and gross salary of the employee as shown here in the second snapshot of the sample run:

print gross bonus of basic salary c

Here are some of the main steps used in the above program:

Before closing the discussion on this post, I'm willing to include one more example that does the same job of calculating and printing the bonus and gross salary based on the basic one. I used comments to describe the main codes used in the following C program:

C Code
#include <stdio.h>

int main() {
    float basic_salary, bonus, gross_salary;

    printf("Enter basic salary: ");
    scanf("%f", &basic_salary);

    // Calculate bonus based on basic salary
    if (basic_salary <= 10000) {
        bonus = basic_salary * 0.1;
    } else if (basic_salary <= 20000) {
        bonus = basic_salary * 0.15;
    } else {
        bonus = basic_salary * 0.2;

    // Calculate gross salary
    gross_salary = basic_salary + bonus;

    // Print bonus and gross salary
    printf("Bonus: %.2f\n", bonus);
    printf("Gross salary: %.2f\n", gross_salary);

    return 0;
Enter basic salary: 25000
Bonus: 5000.00
Gross salary: 30000.00

C Quiz

« Previous Program Next Program »

Liked this post? Share it!