# Algo

 Rehman . · April 4, 2015 i want to ask an algo of a problem which is : "Take an array and program it like it should print the smallest number " it should be like linear sort but dont sort it

## Replies

- page 1

 Dol Lod · April 4, 2015 I have no idea what you are talking about sorting for. However the easiest way to do this is the following.If the array is NULL,{      throw an exception.}Set min to be the first element in the array.For each element in the array,{      if the element is less than min,       {            set min to the element's value      }}.Print out min. Is this what you mean, I am not soring at all and this will give the minimum value of the array.Code is now indented for clarification although apparently changes cannot be seen. As a workaround, I added braces. Rehman . · April 4, 2015 didn't get your answer, sorry Dol Lod · April 4, 2015 That is pseudocode for getting the minimum value in an array or container. To be fair, I don't really get what your question is asking. I assumed it was asking for how to get the minimum value in an array. Rehman . · April 5, 2015 yes this is my question "How to get the minal value" but how can you place a minimum value to to the first index ? maybe user can give the minum value to the 3rd index , second you are using a "for each loop" ? i guess this is for java! C++ can't do that Dol Lod · April 5, 2015 C++ actually can use extended for loops now. Anyway, here is specific code. Anyway, that was pseudocode. Here is the same algorithm I described in a specific example. ``#include int array[5]={3,5,1,4,2}; //used as a specific arrayint arrayLength=5; //used for the array sizeint min=array[0]; //sets min to the first elementfor(int position=0;position
• 1
• 2

## General Chat

120,838 followers