48 lines
1.1 KiB
C
48 lines
1.1 KiB
C
#include <stdio.h>
|
|
|
|
// Question 1:
|
|
// Function to find maximum
|
|
int find_maximu m(const int arr[], int len) {
|
|
int max = arr[0];
|
|
for(int i = 0; i < len; i++) {
|
|
if(arr[i] > max) {
|
|
max = arr[i];
|
|
}
|
|
}
|
|
return max;
|
|
}
|
|
|
|
// Function to find minimum
|
|
int find_minimum(const int arr[], int len) {
|
|
int min = arr[0];
|
|
for(int i = 0; i < len; i++) {
|
|
if(arr[i] < min) {
|
|
min = arr[i];
|
|
}
|
|
}
|
|
return min;
|
|
}
|
|
|
|
// Function to find amount temperatures above given threshold
|
|
int above_threshold(const int arr[], int len, int threshold) {
|
|
int count = 0;
|
|
for(int i = 0; i < len; i++) {
|
|
if(arr[i] > threshold)
|
|
count++;
|
|
}
|
|
return count;
|
|
}
|
|
// Passed arrays are const because they shouldn't be modified in the functions
|
|
|
|
int main() {
|
|
// The array of temps, and threshold value to be used to test
|
|
int temps[7] = {32,35,30,28,40,33,29};
|
|
int threshold = 32;
|
|
|
|
printf("Maximum Temperature: %d\n", find_maximum(temps, 7)); // Max test
|
|
printf("Minimum Temperature: %d\n", find_minimum(temps, 7)); // Min test
|
|
printf("Days above Threshold (%d): %d", threshold, above_threshold(temps, 7, threshold)); // Threshold test
|
|
|
|
return 0;
|
|
}
|