Answered by:
Smallest number in an array
Question

How do I find the smallest number in an array of numbers? I couldn't find any examples in small basic. I tried to look at examples in other programming languages, but I couldn't find a pattern. I thought maybe I could use bubble sort but realized I just need to get the smallest number regardless of the order of the numbers. Thanks in advance.
Answers

Or without extensions, check each array value:
Arr[1]=5 Arr[2]=8 Arr[3]=7 Arr[4]=2 Arr[5]=4 minArr = Arr[1] For i = 2 To Array.GetItemCount(Arr) minArr = Math.Min(minArr,Arr[i]) EndFor TextWindow.WriteLine("Minimum is "+minArr)
 Marked as answer by Ezra94 Friday, July 11, 2014 1:21 AM

Or again with LitDev extension:
Arr[1]=5 Arr[2]=8 Arr[3]=7 Arr[4]=2 Arr[5]=4 MyList = LDList.FromArray(Arr) LDList.SortByNumber(MyList) minArr = LDList.GetAt(MyList,1) TextWindow.WriteLine("Minimum is "+minArr)
Or again without extension:
Arr[1]=5 Arr[2]=8 Arr[3]=7 Arr[4]=2 Arr[5]=4 minArr = Arr[1] For i = 2 To Array.GetItemCount(Arr) If Arr[i] < Arr[i1] Then minArr = Arr[i] EndIf EndFor TextWindow.WriteLine("Minimum is "+minArr)
 Marked as answer by Ezra94 Friday, July 11, 2014 1:26 AM
All replies



Or without extensions, check each array value:
Arr[1]=5 Arr[2]=8 Arr[3]=7 Arr[4]=2 Arr[5]=4 minArr = Arr[1] For i = 2 To Array.GetItemCount(Arr) minArr = Math.Min(minArr,Arr[i]) EndFor TextWindow.WriteLine("Minimum is "+minArr)
 Marked as answer by Ezra94 Friday, July 11, 2014 1:21 AM

Or again with LitDev extension:
Arr[1]=5 Arr[2]=8 Arr[3]=7 Arr[4]=2 Arr[5]=4 MyList = LDList.FromArray(Arr) LDList.SortByNumber(MyList) minArr = LDList.GetAt(MyList,1) TextWindow.WriteLine("Minimum is "+minArr)
Or again without extension:
Arr[1]=5 Arr[2]=8 Arr[3]=7 Arr[4]=2 Arr[5]=4 minArr = Arr[1] For i = 2 To Array.GetItemCount(Arr) If Arr[i] < Arr[i1] Then minArr = Arr[i] EndIf EndFor TextWindow.WriteLine("Minimum is "+minArr)
 Marked as answer by Ezra94 Friday, July 11, 2014 1:26 AM



Ezra94,
Yes, you need to download an extension. The LItDev extension is the one I used for the example.
To get it type smallbasic.com in for the URL in your browser. When the page opens down on the lower right you will see where it says extensions. Click on that and a new page opens. It shows a list of extensions. Choose the LitDev extension and click on it. Another page will open and download . Extract the files as they are in a Zip container. The LitDev.dll and LitDev.xml files are what you need to load into Small Basic.
Find where Small Basic is loaded on your computer. Create a folder called Lib. Place the 2 files that I mentioned in the Lib Folder. Then start Small Basic. Type in LD and you should see a function called LD3DView pop up in the intellisense. From there you will find a bunch of added functions from the extension.
By the way, the LitDev extension is the best. It works great and is well supported by LitDev.
JR
