Have a max int and set it to the first value in the array. Then in a for loop iterate through the whole array and see if the max int is larger than the int at the current index.

int max = array.get(0);

for (int i = 1; i < array.length; i++) {
    if (array.get(i) > max) {
      max = array.get(i);
    }
}
Answer from Philip on Stack Overflow
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ dsa โ€บ program-to-find-largest-element-in-an-array
Largest element in an Array - GeeksforGeeks
Most of the languages have a relevant max() type in-built function to find the maximum element, such as std::max_element in C++. We can use this function to directly find the maximum element. ... #include <iostream> #include <vector> #include <algorithm> using namespace std; int largest(vector<int>& arr) { return *max_element(arr.begin(), arr.end()); } int main() { vector<int> arr = {20, 10, 20, 4, 100}; cout << largest(arr); return 0; }
Published: 3 days ago
๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ JavaScript โ€บ Reference โ€บ Global_Objects โ€บ Math โ€บ max
Math.max() - JavaScript - MDN Web Docs
The Math.max() static method returns the largest of the numbers given as input parameters, or -Infinity if there are no parameters. console.log(Math.max(1, 3, 2)); // Expected output: 3 console.log(Math.max(-1, -3, -2)); // Expected output: -1 const array = [1, 3, 2]; console.log(Math.max(...
Discussions

How to find maximum value of an Array
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://imgur.com/a/fgoFFis ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
๐ŸŒ r/javahelp
26
7
June 22, 2022
java - How to find the maximum value in an array? - Stack Overflow
In java, i need to be able to go through an array and find the max value. How would I compare the elements of the array to find the max? More on stackoverflow.com
๐ŸŒ stackoverflow.com
Finding the max value of a property in an array of objects
FWIW my understanding is when you call apply on a function it executes the function with a specified value for this and a series of arguments specified as an array. The trick is that apply turns the array into a series of actual function arguments. So in this case it finally calls Math.max(0.0265, ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Help With Function to find MAX value in Array
I am new to Rust and trying to make a function to return the max value of an array and reverse an array: The following code works but is not a function: fn main() { let arr: [i64; 5] = [1, 2, 3, 4, 5]; let mut large: i64 = 0; let mut i: usize = 0; large = arr[0]; while i More on users.rust-lang.org
๐ŸŒ users.rust-lang.org
3
0
April 17, 2023
๐ŸŒ
Real Python
realpython.com โ€บ numpy-max-maximum
NumPy's max() and maximum(): Find Extreme Values in Arrays โ€“ Real Python
October 22, 2025 - The .max() method has scanned the whole array and returned the largest element. Using this method is exactly equivalent to calling np.max(n_scores). But perhaps you want some more detailed information.
๐ŸŒ
MathWorks
mathworks.com โ€บ matlab โ€บ data import and analysis โ€บ descriptive statistics and insights
max - Maximum elements of array - MATLAB
For example, for a vector A = [-1 2 -9], the syntax max(A,[],"ComparisonMethod","abs") compares the elements of A according to their absolute values and returns a maximum value of -9. ... Create a vector and compute its largest element. ... Create a complex vector and compute its largest element, that is, the element with the largest magnitude. ... Create a matrix and compute the largest element in each column. ... Create a matrix and compute the largest element in each row. ... Create a 3-D array and compute the maximum over each page of data (rows and columns).
๐ŸŒ
Built In
builtin.com โ€บ articles โ€บ javascript-array-max
3 Ways to Find the Maximum Value in a JavaScript Array
Arrays are a versatile structure in JavaScript that holds multiple data types. Find the maximum value in an array using for loop, math.max() and the reduce method.
Find elsewhere
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ c language โ€บ how-to-find-maximum-value-in-an-array-in-c
How to Find Maximum Value in an Array in C? - GeeksforGeeks
July 23, 2025 - We 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.
๐ŸŒ
Medium
medium.com โ€บ @amitsharma_24072 โ€บ 3-efficient-ways-to-find-maximum-value-in-javascript-arrays-515463ebd17
3 Efficient Ways to Find Maximum Value in JavaScript Arrays | by Amit Sharma | Medium
July 11, 2024 - The Math.max() function is a built-in JavaScript function that takes any number of arguments and returns the maximum value. By using the spread operator (โ€ฆ) and applying it to the array:
๐ŸŒ
Medium
medium.com โ€บ @jgoz โ€บ finding-the-max-value-in-an-array-62328468128b
Finding the Max Value in an Array | by Jeff Gosselin | Medium
September 2, 2019 - The variable we created is called max and initialized with the value of -1. Why -1? As I mentioned before, we do not have to worry about the array including negative values, so therefore we can start with max being -1 and not worry about the first value in the array being less than it.
๐ŸŒ
W3Schools
w3schools.com โ€บ php โ€บ func_math_max.asp
PHP max() Function
"<br>"); echo(max(array(44,16,81,12))); ?> Try it Yourself ยป ... The max() function returns the highest value in an array, or the highest value of several specified values.
๐ŸŒ
Code Maze
code-maze.com โ€บ home โ€บ how to find the maximum value of an array in c#
How to Find the Maximum Value of an Array in C# - Code Maze
July 13, 2022 - To find the maximum element manually, first, we need to initialize the maxElementvariable filling it with our arrayโ€™s first element. Then we loop through our array checking if each element is greater than our maxElement value.
๐ŸŒ
Rust Programming Language
users.rust-lang.org โ€บ code review
Help With Function to find MAX value in Array - code review - The Rust Programming Language Forum
April 17, 2023 - I am new to Rust and trying to make a function to return the max value of an array and reverse an array: The following code works but is not a function: fn main() { let arr: [i64; 5] = [1, 2, 3, 4, 5]; let mut large: i64 = 0; let mut i: usize = 0; large = arr[0]; while i
๐ŸŒ
Vultr Docs
docs.vultr.com โ€บ python โ€บ third party โ€บ numpy โ€บ max()
Python Numpy max() - Find Maximum Value
November 18, 2024 - Include negative and floating-point numbers in your array to handle diverse data sets. Apply max() to find the highest number. ... Regardless of the mix of negative and positive floating-point numbers, .max() correctly identifies 5 as the maximum ...
๐ŸŒ
Arduino Forum
forum.arduino.cc โ€บ projects โ€บ programming
find maximum value in array - Programming - Arduino Forum
April 30, 2016 - Hi , i need to find the maximum value in array of 140 elements , and the index associated with this max value to use it in the code again . please help me, and thank you so much ๐Ÿ˜ƒ
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ java-program-for-program-to-find-largest-element-in-an-array
Java Program to Find Largest Element in an Array - GeeksforGeeks
The most common method to find and print the largest element of a Java array is to iterate over each element of the array and compare each element with the largest value. ... We assume that the first element is the largest and initialize the ...
Published: March 26, 2026
๐ŸŒ
Programiz
programiz.com โ€บ c-programming โ€บ examples โ€บ array-largest-element
C Program to Find Largest Element in an Array
#include <stdio.h> int main() { int n; double arr[100]; printf("Enter the number of elements (1 to 100): "); scanf("%d", &n); for (int i = 0; i < n; ++i) { printf("Enter number%d: ", i + 1); scanf("%lf", &arr[i]); } // storing the largest number to arr[0] for (int i = 1; i < n; ++i) { if (arr[0] < arr[i]) { arr[0] = arr[i]; } } printf("Largest element = %.2lf", arr[0]); return 0; }
๐ŸŒ
Reddit
reddit.com โ€บ r/homeworkhelp โ€บ [c programming: finding maximum element in an array using functions] what's wrong with my code?
r/HomeworkHelp on Reddit: [C Programming: Finding Maximum Element in an Array Using Functions] What's wrong with my code?
April 22, 2021 -

So I made a function to determine the maximum element of an array of integers. But when I try to print the value of the maximum element, it gives me a weird large number 1619117764., and isn't what I'm expecting. What am I doing wrong? Thank you so much in advance.

This is the error message:

C:\Users\USER\Desktop\Discrete Math\Max Value.c|25|warning: passing argument 1 of 'max_value' makes pointer from integer without a cast [-Wint-conversion]|

Here is my code:

#include <stdio.h>

int max_value (int input[])
{
 int size=10, max;
 max=input[0];

 for(int i=1;i<size;i++)
 {
     if(max<input[i])
     {
         max = input[i];
     }
 }

 return max;
}


int main ()
{
    int x, max;
    int input[] = {2, 3, 5, 10, 15, 42, 28, 88, 92};

    x = max_value(max);
    printf("/n The Max is: %d" ,x);

    return 0;
}
๐ŸŒ
BinaryFish
binary-fish.vercel.app โ€บ blog โ€บ pythonmaxmin
How to get max and min value of an array in python.
January 8, 2024 - To get the maximum value of an array, you can use the max() function. Just like the min() function, the min() function will return the maximum value of a data set(including variables and arrays) given inside the brackets ().