C++, Can you please tell me how can I display the smallest variable in an array ? MY CODE: while (counter < 9){ if (B[i] < B[i+u]) i++; else if (B[i+u] < B[i]){ B[i] = B[i+u]; } counter++; }
MY NEW CODE: while (counter < 9){ if (B[i] <= B[u]) u++; else { B[i] = B[u]; u++; } counter++; }
That solution I did for the other problem you had would work. Just set your test variable to the first one then loop through. Also, a sort could work. Then reurn the 0th element of the sorted array.
What is a sort ? Can you please give me an example of how to code something that finds the smallest variable?
Have the link to the solution I shared for your last problem?
temp=array[0] loop through array if temp>array[iter] temp = array[iter]
FIXED !!!!! Thanks a lot bro !! :) while (counter < 9){ if (B[i] <= B[u]) u++; else { i++; B[i]=B[u]; u++; } counter++; }
Looks like you are doing a sort. Well, that works.
Join our real-time social learning platform and learn together with your friends!