I'm running a loop where I'm trying to find the smallest value in an array. Does anyone know of a way in which I can assign the first value in the first pass to the variable that is supposed to hold the smallest value in such a way that I don't have to add a conditional statement saying that if i = 0 to automatically assign it. I also don't want to initialize the variable to some ridiculously large number. For example:
Code:int minimum_value = 10000000 // I don't want to do this . . . . . for(i=0;array[i]<elements;i++) { if(i==0) minimum_value = array[i]; // I don't want to have to do this if(array[i] < minimum_value) minimum_value = array[i]; } . . . . .



LinkBack URL
About LinkBacks





