www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - [your code here]

module main;

import std.stdio;
import std.random;

T[] getSmallest(T)(T[] arr)
{
     if (arr.length>=2)
     {
         auto left=getSmallest(arr[0..$/2]);
         auto right=getSmallest(arr[$/2..$]);

         if (left<=right)
         {
             return left;
         }

         return right;
     }

     return arr[];
}

int main(string[] args)
{
     int max=uniform(1,20);
     int[] array=new int[max];

     //set values to array
     foreach (ref elem;array)
     {
         elem=uniform(10,100);
          write(elem," ");
     }

     writeln();

     //get the smallest element in array
     auto smallest=getSmallest(array);

     //print it
     writeln("smallest: ",smallest);
	return 0;
}
May 03 2019