Ankita Saini has Published 319 Articles

Swift Program to find the second largest element from the array

Ankita Saini

Ankita Saini

Updated on 06-Apr-2023 08:37:22

3K+ Views

In Swift, we can find the second largest element from the given array using the sort() function or using user defined function. For example, we have the following array − Array = [34, 23, 1, 45, 3] Hence the largest element is 45 and the second largest element is ... Read More

Swift Program to Check if two sets are equal

Ankita Saini

Ankita Saini

Updated on 06-Apr-2023 08:36:32

295 Views

Swift provide an equality operator(==) to check if the given two sets are equal or not. Here the equality of two the sets means that both the sets should be identical in terms of their size and elements. So if both the sets are identical or the same, then the ... Read More

Swift Program to Check if a Set is empty

Ankita Saini

Ankita Saini

Updated on 06-Apr-2023 08:36:24

488 Views

In Swift, a set is used to create a collection of unique elements. In a set, the elements are not arranged in a particular order. Now to check if a set is empty or not Swift provide an inbuilt property named as isEmpty. This property will return true if the ... Read More

Swift Program to Convert an Set of String to Comma Separated String

Ankita Saini

Ankita Saini

Updated on 06-Apr-2023 08:35:04

2K+ Views

Swift provide a inbuilt method named as joined() to convert a set of string to comma separated string. This function return the concatenated elements of the given sequence by inserting the given separator in between each element of the sequence. Syntax func joined(separator: sep) Where the separator parameter ... Read More

Swift Program to Add Two Complex Numbers by Passing Class to a Function

Ankita Saini

Ankita Saini

Updated on 05-Apr-2023 09:51:25

232 Views

In swift, a complex number is the combination of real and imaginary number. So we create a class to store the real and imaginary part of the complex number and then we pass this class in the function to find the sum of two complex numbers. Algorithm Step 1 ... Read More

Swift Program to Add Elements to a Set

Ankita Saini

Ankita Saini

Updated on 05-Apr-2023 09:44:48

720 Views

In Swift, set is used to create an unordered collection of unique elements. Swift provide inbuilt functions named as formUnion() and insert() function to insert elements to a set. Lets discuss both the methods in detail along with examples. Method 1: Using formUnion(_:) function The formUnion(_:) function is used to ... Read More

Swift Program to print the right diagonal matrix

Ankita Saini

Ankita Saini

Updated on 16-Feb-2023 16:45:03

635 Views

A matrix is an arrangement of numbers in rows and columns. Matrix can be of various type like square matrix, horizontal matrix, vertical matrix etc. So here we print the right diagonal of square matrix. Square matrix is a matrix in which the number of rows and columns are same. ... Read More

Swift Program to print the left diagonal matrix

Ankita Saini

Ankita Saini

Updated on 16-Feb-2023 16:44:06

490 Views

In this article, we will learn how to write a swift program to print the left diagonal matrix. A matrix is an arrangement of numbers in rows and columns. Matrix can be of various type like square matrix, horizontal matrix, vertical matrix etc. So here we print the left diagonal ... Read More

Swift Program to Check whether a number is a Perfect Cube or not

Ankita Saini

Ankita Saini

Updated on 16-Feb-2023 16:43:03

943 Views

A number is a perfect cube if the result of the three time multiplication of a whole number is the number itself. For example: number 5 is a per Number = 125 125 = 5*5*5 Here 125 is a perfect cube. Number = 98 Here 98 is not a perfect ... Read More

Swift Program to Check if the given number is Perfect number or not

Ankita Saini

Ankita Saini

Updated on 16-Feb-2023 16:41:41

526 Views

A perfect number is a positive number that is equal to the sum of its factors, excluding the number itself. For example − Number = 6 Proper divisors = 1, 2, 3 Hence, 6 is the perfect number because the sum of its divisors is 6(1+2+3) Number = 10 Proper ... Read More

Advertisements