#include <stdio.h>
#include <stdlib.h>
// Function to calculate the maximum value in the array
int findMaximum(int arr[], int size) {
int max = arr[0];
for (int i = 1; i < size; i++) {
if (arr[i] > max) {
max = arr[i];
}
}
return max;
}
// Function to calculate the minimum value in the array
int findMinimum(int arr[], int size) {
int min = arr[0];
for (int i = 1; i < size; i++) {
if (arr[i] < min) {
min = arr[i];
}
}
return min;
}
// Function to calculate the mean (average) value of the array
float findMean(int arr[], int size) {
int sum = 0;
for (int i = 0; i < size; i++) {
sum += arr[i];
}
return (float)sum / size;
}
// Function to calculate the median value of the array
float findMedian(int arr[], int size) {
// Sort the array
for (int i = 0; i < size - 1; i++) {
for (int j = 0; j < size - i - 1; j++) {
if (arr[j] > arr[j + 1]) {
// Swap arr[j] and arr[j + 1]
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
// Calculate the median
if (size % 2 == 0) {
// If the size is even, average the middle two elements
return (float)(arr[size / 2 - 1] + arr[size / 2]) / 2;
} else {
// If the size is odd, return the middle element
return arr[size / 2];
}
}
int main() {
int size;
// Input the size of the array
printf("Enter the size of the array: ");
scanf("%d", &size);
// Input the elements of the array
int arr = (int )malloc(size * sizeof(int));
printf("Enter the elements of the array:\n");
for (int i = 0; i < size; i++) {
scanf("%d", &arr[i]);
}
// Call the functions to calculate and display the results
printf("Maximum: %d\n", findMaximum(arr, size));
printf("Minimum: %d\n", findMinimum(arr, size));
printf("Mean: %.2f\n", findMean(arr, size));
printf("Median: %.2f\n", findMedian(arr, size));
// Free the allocated memory
free(arr);
return 0;
}