// LargestReturned.swift Copyright (c) Kari Laitinen // http://www.naturalprogramming.com // 2014-10-01 File created. // 2016-11-04 Converted to Swift 3. import Foundation // The following function takes two input parameters and // returns a value of type Int. func search_largest_integer( _ array_of_integers : [ Int ], _ number_of_integers_to_process : Int ) -> Int { var largest_integer = array_of_integers[ 0 ] var integer_index = 1 while integer_index < number_of_integers_to_process { if array_of_integers[ integer_index ] > largest_integer { largest_integer = array_of_integers[ integer_index ] } integer_index += 1 } return largest_integer } // Next is the main program in which the above function is // called twice. var first_array = [ 44, 2, 66, 33, 9 ] var second_array = [ 888, 777, 66, 999, 998, 997 ] var found_largest_integer = search_largest_integer( first_array, 5 ) print( "\n The largest integer in first_array is " + String( found_largest_integer ) + ".\n" ) print( "\n The largest integer in second_array is " + String( search_largest_integer( second_array, 6 ) ) + ".\n\n" )