About Lesson
Program to Find the Maximum Element in an Array
#include <stdio.h>
// Function to find the maximum element in an array
int findMaxElement(int arr[], int size) {
int max = arr[0];
for (int i = 1; i < size; i++) {
if (arr[i] > max) {
max = arr[i];
}
}
return max;
}int main() {
int size;// Taking input for the size of the array
printf(“Enter the size of the array: “);
scanf(“%d”, &size);int array[size];
// Taking input for array elements
printf(“Enter %d elements:n”, size);
for (int i = 0; i < size; i++) {
scanf(“%d”, &array[i]);
}// Calling the function to find the maximum element and printing the result
int maxElement = findMaxElement(array, size);
printf(“Maximum element in the array: %dn”, maxElement);return 0;
}