Found 517 Articles for Swift

Swift Program to find the given number is strong or not

Ankita Saini
Updated on 08-Feb-2023 20:16:57

176 Views

A strong number is a special number in which the sum of the factorial of its digit is equal to the number itself. For example − Number = 345 345! = 3! + 4! + 5! = 6 + 24 + 120 = 150 Here 345 is not a strong number because the sum of the factorial of its digit is not equal to the number itself. Number = 145 145! = 1! + 4! + 5! = 1 + 24 + 120 = 145 Here 145 is a strong number because the sum of the factorial of its ... Read More

Swift Program to find the 1's complement of the given number

Ankita Saini
Updated on 08-Feb-2023 20:17:46

498 Views

1’s complement of a binary number is the invert of the given number. For example, we have a number = 10101011, so the one’s complement is 01010100. Here we using the following two methods to find one’s complement − Replacing 1s with 0s and 0s with 1s Using XOR In this article, we will learn how to write a swift program to find the 1’s complement of the given number. Method 1: Replacing 1s with 0s and 0s with 1s It is the smallest method to find ons complement of the given number. Here we simply convert the given number ... Read More

Swift Program to Convert Array to Set

Ankita Saini
Updated on 08-Feb-2023 20:19:03

6K+ Views

An array is used to store elements of the same data type in an order whereas a set is used to store distinct elements of the same data type without any definite order. To convert Array into set we use Set() initialiser. The resultant set contains the same elements as the original array but with no order and no duplicate elements. In this article, we will learn how to convert Array to Set using Swift programming language. Algorithm Step 1 − Create an array of integer type. Step 2 − Print the array. Step 3 − Convert array into ... Read More

Swift Program to check whether a given string is Heterogram or not

Ankita Saini
Updated on 08-Feb-2023 21:13:54

122 Views

Heterogram string is a string in which no alphabet occurs more than once. For example, “Sky with cloud” is a heterogram because in the string each alphabet occurred only once. Whereas “colorful balloons” is not a Heterogram because in the string some alphabet like o, u, l, etc appears more than once. Here we will execute different examples that will check whether the given string is heterogram or not using swift programming language. Algorithm Step 1 − Create a function. Step 2 − Remove the white space from the string. Step 3 − Create a separate array to ... Read More

Swift program to check if string is pangram or not

Ankita Saini
Updated on 08-Feb-2023 21:14:22

433 Views

Pangram string is a string that contains all the English alphabet. For example − String = “The quick brown fox jumps over the lazy dog” Here the string is a pangram string which contains all the alphabetical characters from a to z in it. String = “ Hello! Swati how are you?” Here the string is not a pangram string because it does not contain all the 26 alphabetical characters from a to z. In this article, we will learn how to write a swift program to check if a string is pangram or not. So to check if the ... Read More

Swift Program to check if an Array is Palindrome or not

Ankita Saini
Updated on 08-Feb-2023 20:20:39

3K+ Views

A palindrome array is an array that remains the same when its elements are reversed we can also say that the elements of a palindrome array remain the same even if we read it from backward or forward. For example, [1, 9, 10, 9, 1] is a palindrome array whereas [3, 5, 7, 8, 3, 2, 1] is not a palindrome array. In this article, we are going to learn different methods of finding whether the given array is a palindrome or not suing Swift programming language. Algorithm Step 1 − Create a function. Step 2 − Reverse the ... Read More

Swift Program to check if a given string is Keyword or not

Ankita Saini
Updated on 08-Feb-2023 20:21:51

211 Views

Keywords are reserved words used to perform some internal process or represent predefined actions. It is not allowed to use these keywords as a variable name, constant name, or identifier. Swift support approx 101 keywords. For example, ‘var’ is a keyword but ‘hey’ is not a keyword. Here, we will learn how to write a swift program to check whether a given string is a keyword. Algorithm Step 1 − Create an array of string types to store all the keywords supported by Swift. Step 2 − Create a function to check if the given string is a ... Read More

Swift Program to remove the last given number of items from the array

Ankita Saini
Updated on 27-Jan-2023 12:38:26

182 Views

In this article, we will learn how to write a swift program to remove the last given number of items from the array. An array is used to store elements of same data type in an order. So, here we use the following methods to remove the last given number of items from the array − Using removeLast(_:) function Using dropLast(_:) function Using removeSubrange() function Method 1: Using removeLast(_:) Function Swift provide an in-built function named as removeLast() function to remove the specified number of items from the end of the array. Syntax func removeLast(_x: Int) ... Read More

Swift Program to remove the first given number of items from the array

Ankita Saini
Updated on 27-Jan-2023 12:34:59

307 Views

In this article, we will learn how to write a swift program to remove the first given number of items from the array. An array is used to store elements of same data type in an order. So, here we use the following methods to remove the first given number of items from the array − Using removeFirst(_:) function Using dropFirst(_:) function Using removeSubrange() function Method 1: Using removeFirst(_:) Function Swift provide an in-built function named as removeFirst() function to remove the specified number of items from the start of the array. Syntax func removeFirst(_x: Int) ... Read More

Swift Program to Print object of a class

Ankita Saini
Updated on 27-Jan-2023 12:33:02

1K+ Views

In this article, we will learn how to write a swift program to print object of a class. A class object is known as an instance of a class. For example, colour is a class then obj1, obj2, obj3 and obj4 are the objects from the class. A class can have multiple objects. Syntax var objectname = Classname() Here, using the above syntax we can create an object of a class. Algorithm Step 1 − Create a class with properties and a constructor. Step 2 − Create a function to print the object of the given class. Step ... Read More

Advertisements