How to Find Maximum Value in an Array in C? Last Updated : 23 Jul, 2025 Comments Improve Suggest changes 3 Likes Like Report In C, arrays are data structures that allow the user to store a collection of data of the same type. In this article, we will learn how we can find the maximum value in an array in C. Example Input: arr = {5,3,1,2,4} Output: The maximum value of the array is: 5Finding Maximum Value in an Array in CWe can find the maximal value in an array by taking a variable max and repeatedly comparing it to the elements of the array using loops. AlgorithmInitialize a variable maxVal with value arr[0].Traverse through the whole array. During traversal:If maxVal is less than the current value of array update the value of maxVal.Else continue.Exit the loop after whole traversal and Print res which denotes the maximum value in array. C Program to Find the Maximum Value in an Array C // C program to find maximum value in an array #include <stdio.h> int main() { // Initialize an array int arr[] = { 23, 12, 45, 20, 90, 89, 95, 32, 65, 19 }; // Find the size of the array int n = sizeof(arr) / sizeof(arr[0]); // Intialize the variable which will denote the maximum // element int res = arr[0]; // Find the maximum value in the array and store it in // res for (int i = 0; i < n; i++) { if (res < arr[i]) res = arr[i]; } // print the elements of the array printf("Array Elements: "); for (int i = 0; i < n; i++) { printf("%d ", arr[i]); } printf("\n"); // print the maximum value printf("The maximum value of the array is: %d", res); return 0; } OutputArray Elements: 23 12 45 20 90 89 95 32 65 19 The maximum value of the array is: 95Time Complexity: O(N) where N is the number of elements in the array.Auxiliary Space: O(1) Create Quiz Comment T the_star_emperor Follow 3 Improve T the_star_emperor Follow 3 Improve Article Tags : C Programs C Language Basic Coding Problems C-Arrays C Basic Programs C Examples +2 More Explore C BasicsC Language Introduction6 min readIdentifiers in C3 min readKeywords in C2 min readVariables in C4 min readData Types in C3 min readOperators in C8 min readDecision Making in C (if , if..else, Nested if, if-else-if )7 min readLoops in C6 min readFunctions in C5 min readArrays & StringsArrays in C4 min readStrings in C5 min readPointers and StructuresPointers in C7 min readFunction Pointer in C5 min readUnions in C3 min readEnumeration (or enum) in C5 min readStructure Member Alignment, Padding and Data Packing8 min readMemory ManagementMemory Layout of C Programs5 min readDynamic Memory Allocation in C7 min readWhat is Memory Leak? How can we avoid?2 min readFile & Error HandlingFile Handling in C11 min readRead/Write Structure From/to a File in C3 min readError Handling in C8 min readUsing goto for Exception Handling in C4 min readError Handling During File Operations in C5 min readAdvanced ConceptsVariadic Functions in C5 min readSignals in C language5 min readSocket Programming in C8 min read_Generics Keyword in C3 min readMultithreading in C9 min read Like