Course Content
Detailed Content of Programming in C
0/1
Introduction
0/1
Structure of C program
0/1
Answers of ‘C’ Pointers Programs
0/1
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;
}