Calculate employees age
Suppose a company keeps a linear array A (1920:1970) such that A[K] contains the number of employees born in year K, write a module/algorithm for the following tasks:
- Find the number NUM of years in which no employee was born.
- Find the number NUM of employee whose age is not greater 45 years.
- Find the number NUM of employees whose age is an even number
- Find the average AVG age of the employees.
- Find the total number NUM of employee having an age between 40 to 60.
Sample Output
Enter Year(i.e. 1970 to 1990): 1975 1980 Employee Bron 1975: 3 1976: 0 1977: 3 1978: 0 1979: 9 1980: 8 No Employee Was Bron: 2 Employee whose age is not greater 45 years: 6 Employees whose age is an even number: 8 Average age of the employees: 42 Employee having an age between 40 to 60: 6 Process returned 0 (0x0) execution time : 35.168 s Press any key to continue.
C-Source Code
#include<stdio.h>
int main()
{
int i, k, from, to, from2, to2, noEmployeeBorn, current = 2020;
int notGreater45, even, avg, between;
noEmployeeBorn = notGreater45 = even = avg = between = 0;
printf("Enter Year(i.e. 1970 to 1990): ");
scanf("%d %d", &from, &to);
int employeeBorn[to];
k = to - from + 1;
from2 = from;
to2 = to;
printf("Employee Bron\n");
for(i = from; i <= to; i++)
{
printf("%d: ", i);
scanf("%d", &employeeBorn[i]);
}
for(i = from2; i <= to2; i++)
{
if(employeeBorn[i] == 0)
{
noEmployeeBorn++;
}
if((current - i) <= 45)
{
notGreater45++;
}
if((current - i) % 2 == 0)
{
even = even + employeeBorn[i];
}
avg = (avg + (current - i));
if(((current - i) >= 40) && ((current - i) <= 60))
{
between++;
}
}
printf("No Employee Was Bron: %d\n\nEmployee whose age is not greater 45 years: %d\n\nEmployees whose age is an even number: %d\n\nAverage age of the employees: %d\n\nEmployee having an age between 40 to 60: %d\n\n\n", noEmployeeBorn, notGreater45, even, avg / k, between);
return 0;
}
Sample Output
Enter Year(i.e. 1970 to 1990): 1975 1980 Employee Bron 1975: 3 1976: 0 1977: 3 1978: 0 1979: 9 1980: 8 No Employee Was Bron: 2 Employee whose age is not greater 45 years: 6 Employees whose age is an even number: 8 Average age of the employees: 42 Employee having an age between 40 to 60: 6 Process returned 0 (0x0) execution time : 35.168 s Press any key to continue.
No comments:
Post a Comment