Swift Semantics - Hands On.txt - Swift function print_name...

  • No School
  • AA 1
  • amritad123
  • 2
  • 67% (3) 2 out of 3 people found this document helpful

This preview shows page 1 - 2 out of 2 pages.

/* Swift function print_name() that accepts name as input and return the string "Hello <name>" as output */ func print_name(name: String) -> String { return "Hello " + name } let msg = print_name(name: "Pawan") print(msg) /* Swift - Program to add two variables given and print the result on the console */ var x = 10 var y = 20 var z = x + y print(z) /*Swift - Program to add two variables and print the result on the console*/ func add_num(num1: Int, num2: Int) -> Int { let num3 = num1 + num2 return num3 } let num3 = add_num(num1: 1,num2: 3) print(num3) /* Write a program to store given information in different variables and print them. */ func result_tuple(first_name: String, last_name: String, city: String, job: String) -> (fname: String, lname: String,city: String,job: String) { return (first_name,last_name,city,job) } let info = result_tuple(first_name: "John",last_name: "Doe",city: "XYZ City",job: "XYZ Job") /* Write a program to do mathematical operations using tuple. */ func add_num(a: Int, b: Int) -> Int { return a + b } let result = add_num(a: 10,b: 5) /* Write a program to print the lengthiest city from a group of cities. */
Image of page 1
Image of page 2

You've reached the end of your free preview.

Want to read both pages?

  • Fall '19
  • Swift function print

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture