Solution for HW in IOS
import UIKit
//zeev mindali - IOS
//solution #1
//recursive print number from given number to 0
func printRec(var num:Int)
{
if (num==0)
{
//we got to last number, print it and return
print(num);
return;
}
else
{
//print the number
print(num);
//call the function again by reducing the number by one
printRec(--num);
return;
}
}
printRec(10);
//solution #2
//recursive print of array
func printArray(stringArray:Array<String>, num:Int)
{
if (num==0)
{
//if the last item, print it and return
print(stringArray[num]);
//return we finshed
return;
}
else
{
//print the item
print(stringArray[num])
var counter:Int=num;
//call the function again to print it
printArray(stringArray,num: --counter);
//finished the called func and move to upper func
return;
}
}
var myArray:Array<String> = ["Zeev","Amital","Nipo"];
printArray(myArray, num: myArray.count-1);
//solution #3
func combainString( leftString:String, rightString:String ,midString:String=" ")
{
print("\(leftString)\(midString)\(rightString)");
}
combainString("zeev",rightString: "Mindali");
If the answers is incorrect or not given, you can answer the above question in the comment box. If the answers is incorrect or not given, you can answer the above question in the comment box.