This is it:
First let's assume these are the user inputs in the array:
Index Value
0 2
1 3
3 7
4 1
5 9
then it assigns 2 to the variables max,mid & low because, it assigns the value contained by the first element in the array to max & mid & low:
1 2
|
max=array[0];
low=array[0];
|
the the
for loop:
1 2 3 4 5 6 7 8 9 10 11
|
for (int i=0 ; i<5; i++)
{
if ( max<array[i])
{
max=array[i];
}
else if ( low>array[i])
{
low=array[i];
}
}
|
first, this
for loop, declares and initializes an int i to 0:
int i=0
then if i<5 the loop will work!!! because that is the condition, and it is met because i=0 also i++ means i should increase by 1, any time the loop fully works!
in the loop, there is an if statement that checks if the current value in max(which is 2 in my example) is lesser than the value in the first element of the array.
if(max<array[i]) //here i's value is 0 on the first run of the loop and is equivalent to array[0]
and it is not so it does not meet the condition and therefore moves on to the else if statement, which works just like the first if statement.
then when it finishes, it increases i by 1 and checks the condition again, which is eventually met.
So it goes to the if, this time i=1 and not 0
so since array[1] or array[1]=3, max would be given the value array[1] contains, which is 3.
It does this until the for loop eventually ends.
Then it displays max and min, which would eventually be 9 and 1 respectively!!! computer stuff !!!LOL!!!