/* Does this mean that min_val and max_val have been assigned 10?*/
Yes.
1 2 3 4 5 6
for (i=0; i<10; i++){ // start at nums[0], for all terms in the array
if (nums[i] < min_val) min_val= nums[i]; // if the current term is lower than the registered lowest value,
// set the current term to be the lowest registered value
if (nums[i] > max_val) max_val= nums [i]; // if the current term is greater than the registered largest value,
// set the current term to be the largest registered value
}
There's a error in your code. for (i= 1; i<10; i++)\\It was 11, it should be 1
Here's the explanation of what's going on:
First min_val and max_val are assigned the value 10.
Then the program will go into the loop.
There it will check that if num[1] is less than min_val. If it is, then num[1] will be less than num[0]. Hence num[1] will be the minimum value for now.
This will happen in the case of maximum value as well.
I hope that explains it.
EDIT:
@toexii: No need to start the loop with 0 because both the members have the value of num[0]
min_val=max_val=nums[0]; /* Does this mean that min_val and max_val have been assigned 10?*/
Yes it does.
The code iterates through all 10 array elements checking if the value it in the current element is more/less than the current value for min_val/max_val, if it is then it takes on the value of the current element.
If you can't read code like this I strongly recommend you complete at least a few more tutorials before continuing.
@toexii: No need to start the loop with 0 because both the members have the value of num[0]
Yea I realized that later, but it doesn't hurt either, and mostly I iterate through an entire array, so I just left it there for the sake of habit, but you're right.