Ask your own question, for FREE!
Computer Science 8 Online
OpenStudy (christos):

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++; }

OpenStudy (christos):

MY NEW CODE: while (counter < 9){ if (B[i] <= B[u]) u++; else { B[i] = B[u]; u++; } counter++; }

OpenStudy (e.mccormick):

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.

OpenStudy (christos):

What is a sort ? Can you please give me an example of how to code something that finds the smallest variable?

OpenStudy (e.mccormick):

Have the link to the solution I shared for your last problem?

OpenStudy (e.mccormick):

temp=array[0] loop through array if temp>array[iter] temp = array[iter]

OpenStudy (christos):

FIXED !!!!! Thanks a lot bro !! :) while (counter < 9){ if (B[i] <= B[u]) u++; else { i++; B[i]=B[u]; u++; } counter++; }

OpenStudy (e.mccormick):

Looks like you are doing a sort. Well, that works.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!