Find Largest Value in Array C Arduino Uno

Posted on

Largest Value in C

How to Find Largest Value in Array in C Arduino – How to Find the Largest Value in an Array on C Arduino – In Arduino programming, maybe we will encounter a condition where we have to get the largest value from the existing value.

In this article we will learn how to get the largest value from the value stored in an array. For example, there are values 34, 32, 4, 67, 87 and 12. The Arduino IDE will display the largest value, which is 87.

Basic Code:

int values[] = {34, 32, 4, 67, 87, 12};
int largest = 0;
int a;

void setup()
{
  Serial.begin(9600);

  for (int a = 0; a < 6;  a++)
  {
    if (values[a] > largest) {
      largest = values[a];
    }
  }
  Serial.println(largest);
}

void loop() {
}

Output: 87

The code above has 6 known arrays. The array is read one by one from 0 to the 5th address. Initially, the highest value is 0 then compared to the 0th array value.

If the value of the 0 array is greater than the highest value “0”, then the value of the 0 array is entered as highest. If highest value is smaller than 1st array, then continue comparing with 2nd array. Etc.

I hope this tutorial is useful.

May be you like:
If you wanto to find smallest number, please use basic code here.

1 comment

Leave a Reply

Your email address will not be published.