Write a C program to calculate overtime pay of 10 employees. Overtime is paid at the rate of Rs 12 per hour for every hour worked above 40 hours. Assume that employees do not work for fractional part of an hour.
Related Read:
while loop in C programming
if else statement in C
Relational Operators In C
We ask the user to enter the number of hours each employee has worked. Then we calculate overtime worked by each employee. 40 hours is considered normal work hours. Whatever number of hours worked above 40 hours will be considered for Overtime Pay. We calculate the Overtime worked and then for every hour we pay Rs 12 as Overtime pay.
Video Tutorial: C Program To Calculate Overtime Pay of 10 Employees
#include<stdio.h> int main() { int hours, count = 1, ot = 0; while(count <= 10) { printf("\nEnter no of hours employee %d has worked\n", count); scanf("%d", &hours); if(hours > 40) { ot = ot + (hours - 40); printf("Employee %d has worked %d hours\n", count, hours); printf("Overtime pay is Rs %d\n", (hours-40)*12); } else { printf("no of hours worked is %d, which is less than 40 hours, so no over time pay for employee %d\n", hours, count); } count++; } printf("\nTotal Overtime pay is Rs %d\n", (ot*12)); return 0; }
Output:
Enter no of hours employee 6 has worked
45
Employee 6 has worked 45 hours
Overtime pay is Rs 60
Enter no of hours employee 7 has worked
39
no of hours worked is 39, which is less than 40 hours, so no over time pay for employee 7
Enter no of hours employee 8 has worked
41
Employee 8 has worked 41 hours
Overtime pay is Rs 12
Enter no of hours employee 9 has worked
42
Employee 9 has worked 42 hours
Overtime pay is Rs 24
Enter no of hours employee 10 has worked
43
Employee 10 has worked 43 hours
Overtime pay is Rs 36
Total Overtime pay is Rs 252
For list of all c programming interviews / viva question and answers visit: C Programming Interview / Viva Q&A List
For full C programming language free video tutorial list visit:C Programming: Beginner To Advance To Expert