Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Let us say we have an array called intArray[] with size 'n'
- // To find the largest integer in the array, we simply need to go through the entire array, and ask the question 'is this number greater // than my current greatest number?'
- int currentMax = intArray[0]
- for(int i=1; i < n; ++i){
- if(intArray[i] > currentMax){
- currentMax = intArray[i]
- }
- }
- // After this for statement, the currentMax value is the maximum value of the array
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement