Professional Documents
Culture Documents
MDSD Assignment Swift Programming Arshia Thasnim S Cse-A 1517102016
MDSD Assignment Swift Programming Arshia Thasnim S Cse-A 1517102016
MDSD Assignment Swift Programming Arshia Thasnim S Cse-A 1517102016
Swift Programming
Arshia Thasnim S
Cse-A
1517102016
Program 1 :
print(sum(a:1,b:2))
Program 2 :
Program 3 :
func compute (a:Int , b:Int) -> Bool {
if (a > 0 && b > 0) {
return false
}
return true
}
print(compute(a:1,b:4))
Program 4 :
s = String(last) + s
s.append(first)
return s
}
print(compute(st:"Swift"))
Program 6 :
Program : 7
let c = abs(a-10)
let d = abs(b-10)
if (c == d){
return 0
}
return c < d ? a : b
}
print(compute(a:9,b:12))
Program 8:
func compute (a : [Int]) -> Bool {
print(compute(a:[1,7,33,5,3]))
Program 9 :
Program 10 :
if a.count == 0 {
return 0
}else if a.count == 1{
return a[0]
}else{
return a[0] + a[1]
}
Program 11 :
if a.count == 0 {
return []
} else{
return [a[0] , a[a.count-1]]
}
}
print(compute(a:[5,7,33]))
Program 12 :
print(compute(a:[5,7,33]))
Program 13 :
func compute (a : [Int], b: [Int]) -> Int {
print(compute(a:[5,5] ,b:[10,10] ))
Program 14 :
if a.count < 2 {
return a
}else{
return String(a.prefix(2))
}
}
print(compute(a:"qwe"))
Program 15 :
print(compute(a:"q",b:"w"))
Program 16 :
var changeableA = a
if(a.count > 0){
if(a.suffix(1) == "a"){
changeableA.removeLast()
}
return changeableA
print(compute(a:""))
Output Prediction
37.
1
5
9
13
38. “Bones”
39. Optional(1701)
40. 16
41. “Message one”
42. “Hello, Dave!”
43. 30
44. “Kailee”
45. “Public Relations”
46. Optional(“Barbara”)
47.
0: y
2: i
3: s
48. The length is Still 5 , because the Arrays in Swift are Value Types .
49. The Error is at Line 4 , ‘+’ Operator only takes the Arguments with same type . so
It can be fixed by explicitly Typecasting the Variables op1 , op2 to Double
50. ["cat", "chicken", "dog", "fish"]