How to Calculate Company Bonus on Salary in C Programming | C Programming Examples - 16
Write a C program to Calculate Company Bonus on Salary. How to Calculate Company Bonus on Salary in C programming. Logic to Calculate Company Bonus on Salary in C program.
Question:
A company decides to give bonus to all its employees on new year. A 5% bonus on salary is given to male workers and 10% bonus on salary is given to female workers. Write a C program to enter the salary and gender of the employees. If the salary of the employee is less than 10000, then the employee gets an extra 2% bonus on salary. Calculate the bonus that has to be given to the employee and display the salary that the employee will get?
C Programming Examples:
1. Write a C Program to Calculate Company Bonus on Salary
2. C program to Calculate Company Bonus on Salary
3. How to Calculate Company Bonus on Salary in C Programming
C Program to Calculate Company Bonus on Salary : |
#include<stdio.h>
#include<string.h>
main()
{
int i,j;
float salary,bonus;
char gender;
printf("Enter M for Male and F for Female\n");
scanf("%c",&gender);
printf("Enter Salary\n");
scanf("%f",&salary);
if(gender=='M' || gender=='m')
{
if(salary>10000)
bonus=(float)(salary*0.05);//0.05--5%
else
bonus=(float)(salary*0.07);
}
if(gender=='F' || gender=='f')
{
if(salary>10000)
bonus=(float)(salary*0.1);//0.1--10%
else
bonus=(float)(salary*0.12);
}
salary+=bonus;
printf("Bonus=%.2f\nSalary=%.2f\n",bonus,salary);
}
Output:
Enter M for Male and F for Female
M
Enter Salary
11555
Bonus=577.75
Salary=12132.75
Explanation of Finding Company Bonus on Salary in C Programming :
Initializes :
We will first take two inputs for gender and salary from user using scanf function then Calculate Company Bonus on Salary using following equations.
Using if to check whether the gender is Male or Female.
Given that,
Bonus of Male = 5%
= 5/100
= 0.05 %
Bonus of Female = 10%
= 10/100
= 0.1 %
If salary is less than 10000,then the employee gets an extra 2% bonus on salary.
Now,
Bonus of Male = 5+2%
= 7/100
= 0.07 %
Bonus of Female = 10+2%
= 12/100
= 0.12 %
So, total bonus on salary = salary * percentage of bonus
Finally print the total bonus on salary.
0 Response to Write a C program to Calculate Company Bonus on Salary | C Programming Examples - 16
Post a Comment