Add Q1.C
Initial Q1 code, bassically done, just gotta decide how to do N array of thingy
This commit is contained in:
43
Q1.C
Normal file
43
Q1.C
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
typedef struct Employee {
|
||||||
|
char name[50];
|
||||||
|
int age;
|
||||||
|
double salary;
|
||||||
|
} Employee;
|
||||||
|
|
||||||
|
|
||||||
|
Employee find_highest_salary(Employee arr[], int len) {
|
||||||
|
Employee highest_salary = arr[0];
|
||||||
|
|
||||||
|
for(int i = 0; i < len; i++) {
|
||||||
|
if(arr[i].salary > highest_salary.salary) {
|
||||||
|
highest_salary = arr[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return highest_salary;
|
||||||
|
}
|
||||||
|
|
||||||
|
double average_age(Employee arr[], int len) {
|
||||||
|
double sum = 0;
|
||||||
|
for(int i = 0; i < len; i++) {
|
||||||
|
sum += arr[i].age;
|
||||||
|
}
|
||||||
|
return sum / len;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
Employee arr[5] = {
|
||||||
|
{"George", 20, 500.25},
|
||||||
|
{"Bob", 35, 450.75},
|
||||||
|
{"Cane", 18, 69696969.69},
|
||||||
|
{"Eva", 27, 125.25},
|
||||||
|
{"Abagail", 30, 12.00}
|
||||||
|
};
|
||||||
|
|
||||||
|
printf("%0.02f\n", find_highest_salary(arr, 5).salary);
|
||||||
|
|
||||||
|
printf("Average Employee Age: %0.02f\n", average_age(arr, 5));
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user