int sizeOFarray = 5;
int b[5] = {11, 7, 3, 99, 113};
void setup ()
{
Serial.begin(9600);
int LowestValue = b[0]; // intialising b[i] to be the first index of the array which is 11
Serial.print ("The initial lowest value of this array is b[0] - ");
Serial.println(LowestValue);
for (int i = 1; i < sizeOFarray; i++) // to read the rest of the array
{
Serial.println("-----------------------------------------------------");
Serial.print("Checking b[");
Serial.print (i);
Serial.print ("] - ");
Serial.println (b[i]);
delay (200);
if (b[i] < LowestValue) // i is this means index 1 (which is 7) and if it less than the LowestValue (which is set to 11)
{
LowestValue = b[i]; // than the LowestValue will be updated to 7. Now the value stored in 'LowestValue' is 7
Serial.print ("New lowest value found: ");
Serial.println(LowestValue);
delay (200);
}
else
{
Serial.print ("No change. Lowest value still remains: ");
Serial.println(LowestValue);
delay (200);
}
// the code will do the same for the rest of the indexes in the array and if a lower number than 7 is found, 'LowestValue' will be updated to that value
}
Serial.println("-----------------------------------------------------");
Serial.print ("The Lowest number in the array is: ");
Serial.println (LowestValue);
}
void loop () {}