Done
This commit is contained in:
7
Q1.C
7
Q1.C
@@ -1,4 +1,5 @@
|
||||
#include <stdio.h>
|
||||
// Question 1
|
||||
|
||||
typedef struct Employee {
|
||||
char name[50];
|
||||
@@ -6,7 +7,7 @@ typedef struct Employee {
|
||||
double salary;
|
||||
} Employee;
|
||||
|
||||
|
||||
// Finds and returns employee with the highest salary in array
|
||||
Employee find_highest_salary(Employee arr[], int len) {
|
||||
Employee highest_salary = arr[0];
|
||||
|
||||
@@ -18,6 +19,7 @@ Employee find_highest_salary(Employee arr[], int len) {
|
||||
return highest_salary;
|
||||
}
|
||||
|
||||
// Calculates and returns average age of employees in arr
|
||||
double average_age(Employee arr[], int len) {
|
||||
double sum = 0;
|
||||
for(int i = 0; i < len; i++) {
|
||||
@@ -27,6 +29,7 @@ double average_age(Employee arr[], int len) {
|
||||
}
|
||||
|
||||
int main() {
|
||||
// Main function to test struct and the functions
|
||||
Employee arr[5] = {
|
||||
{"George", 20, 500.25},
|
||||
{"Bob", 35, 450.75},
|
||||
@@ -35,8 +38,10 @@ int main() {
|
||||
{"Abagail", 30, 12.00}
|
||||
};
|
||||
|
||||
// Find highest salary
|
||||
printf("%0.02f\n", find_highest_salary(arr, 5).salary);
|
||||
|
||||
// Find average age
|
||||
printf("Average Employee Age: %0.02f\n", average_age(arr, 5));
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user