📊⚡Beginner
Find Largest Element in Array
Find maximum value
Find the largest element in an array by comparing each element with the current maximum.
Program Code
array_largest.c
C
1#include <stdio.h>23int main() {4 int n;5 6 printf("Enter number of elements: ");7 scanf("%d", &n);8 9 int arr[n];10 printf("Enter %d elements: ", n);11 for (int i = 0; i < n; i++) {12 scanf("%d", &arr[i]);13 }14 15 int max = arr[0]; // Assume first is largest16 for (int i = 1; i < n; i++) {17 if (arr[i] > max) {18 max = arr[i];19 }20 }21 22 printf("Largest element: %d\n", max);23 return 0;24}Output
Enter number of elements: 5
Enter 5 elements: 23 67 12 89 45
Largest element: 89
Related Examples
Want to Learn More?
Explore our comprehensive tutorials for in-depth explanations of C programming concepts.
Browse Tutorials