// Largest.swift Copyright (c) Kari Laitinen // http://www.naturalprogramming.com // 2014-10-10 File created. // 2016-11-04 Converted to Swift 3. import Foundation // The following function takes two input parameters and // and one input/output parameter. Through the inout parameter // the caller gets the Int value. func search_largest_integer( _ array_of_integers : [ Int ], _ number_of_integers_to_process : Int, _ largest_integer : inout Int ) { 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 } } // 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 : Int = 0 search_largest_integer( first_array, 5, &found_largest_integer ) print( "\n The largest integer in first_array is " + String( found_largest_integer ) + ".\n" ) search_largest_integer( second_array, 6, &found_largest_integer ) print( "\n The largest integer in second_array is " + String( found_largest_integer ) + ".\n\n" )