Asian American Pacific Islander Month DDSD 2024.pptx
Array and its functionsI SWIFT
1. Working with array
var arr = [1,2,5,3,4,5]
print(arr.first!)
print(arr.last!)
print(arr.capacity)
print(arr.count)
print(arr.firstIndex(of:5)!)
print(arr.lastIndex(of:5)!)
print(arr.removeLast())
print(arr)
print(arr.capacity)
print(arr.count)
print(arr.randomElement()!)
arr.insert(contentsOf: 100...103, at: 3)
print(arr)
print(arr.popLast())
print(arr.isEmpty)
2. For loop in reverse order
for i in stride(from: 5, to:1, by: -1) {
print(i)
}
Practice Problems
1.Write a program add all the prime numbers
available in array.
2.Write a program to find the factorial of all odd
numbers in array.
3.Write a program to reverse an integer and display
the palindrome integer from the same array.
4.Write a program to fetch the middle(only even)
elements from the array and insert it into another
array of length 5 at position 2.