Session 10 Swift IOS Code

IOS Mobile Application Development        

Session 10 Swift IOS Code

/// Recursion
func numbers(num : Int)
{
  print(num)
  if(num < 10)
  {
    numbers(num: num + 1)
  }
}
numbers(num : 1)

func numbers1(num : Int)
{
  print(num)
  if(num > 1)
  {
    numbers1(num: num - 1)
  }
}
numbers1(num : 10)


// 6! = 6 5 4 3 2 1
func factorial(num : Int) -> Int
{
  if(num == 1)
  {
    return 1
  }
  else
  {
    return num * factorial(num: num - 1)
  }
}
print(factorial(num:3))

1 comment:

Fell free to write your query in comment. Your Comments will be fully encouraged.