Found 517 Articles for Swift

Swift Program to sort the Dictionary

Ankita Saini
Updated on 20-Oct-2022 08:23:58

3K+ Views

This tutorial will discuss how to write swift program to sort a Dictionary. A dictionary is used to store data in the form of key-value pair in the collation without any defined-order. Here the type of the keys are same as well as the type of the values are also same. Each key is behave like an identifier for the associate value inside the dictionary and each value has a unique key. Swift dictionary is just like the real dictionary. It loop up values according to their identifier. Syntax Following is the syntax for creating dictionary − ... Read More

Swift Program to Check the dictionary is Empty

Ankita Saini
Updated on 20-Oct-2022 08:22:29

1K+ Views

This tutorial will discuss how to write swift program to check the dictionary is empty. A dictionary is used to store data in the form of key-value pair in the collation without any defined-order. Here the type of the keys are same as well as the type of the values are also same. Each key is behave like an identifier for the associate value inside the dictionary and each value has a unique key. Swift dictionary is just like the real dictionary. It loop up values according to their identifier. Syntax Following is the syntax for creating dictionary − var ... Read More

Swift Program to Find the Size of Dictionary

Ankita Saini
Updated on 20-Oct-2022 08:21:01

764 Views

This tutorial will discuss how to write swift program to find the size of dictionary. A dictionary is used to store data in the form of key-value pair in the collation without any defined-order. Here the type of the keys are same as well as the type of the values are also same. Each key is behave like an identifier for the associate value inside the dictionary and each value has a unique key. Swift dictionary is just like the real dictionary. It loop up values according to their identifier. Syntax Following is the syntax for creating dictionary − var ... Read More

Swift Program to display Armstrong Numbers Between Intervals Using Function

Ankita Saini
Updated on 20-Oct-2022 08:19:43

264 Views

This tutorial will discuss how to write Swift program to display Armstrong numbers between intervals using function The sum of nth power of individual digit of a number is equal to the number itself, then such type of number is known as Armstrong number. Suppose we have a number 407 so here n = 3 407 = 43 + 03 + 73 407 = 64 + 0 +343 407 = 407 Hence 407 is Armstrong number Suppose we have another number 2346, so here n = 4 2346 = 24 + 34 + 44 + 64 2346 = 16 + ... Read More

Swift Program to Check Armstrong Number

Ankita Saini
Updated on 20-Oct-2022 08:18:16

993 Views

This tutorial will discuss how to write swift program to check Armstrong number. The sum of nth power of individual digit of a number is equal to the number itself, then such type of number is known as Armstrong number. Suppose we have a number 407 so here n = 3 153 = 13 + 53 + 33 153 = 1 + 125 + 27 153 = 153 Hence 153 is Armstrong number Suppose we have another number 8973, so here n = 4 8973 = 84 + 94 + 74 + 34 8973 = 4096 + 6561 + 2401 ... Read More

Swift Program to Display Armstrong Number Between Two Intervals

Ankita Saini
Updated on 20-Oct-2022 08:16:41

310 Views

This tutorial will discuss how to write swift program to display Armstrong number between two intervals. The sum of nth power of individual digit of a number is equal to the number itself, then such type of number is known as Armstrong number. Suppose we have a number 407 so here n = 3 407 = 43 + 03 + 73 407 = 64 + 0 +343 407 =407 Hence 407 is Armstrong number Suppose we have another number 2346, so here n = 4 2346 = 24 + 34 + 44 + 64 2346 = 16 + 81 + ... Read More

Swift Program to Find Geometric Mean of the Numbers

Ankita Saini
Updated on 20-Oct-2022 08:14:29

220 Views

This tutorial will discuss how to write swift program to find the geometric mean of the numbers. Geometric mean also known as GM. Geometric mean is defined as the xth root of the product of x numbers. Suppose we have x elements(that are, a1, a2, a3, ....ax) in the given array, then the geometric mean is − GM = (a1 * a2 * a3 * a4 * ....*ax)1/x Below is a demonstration of the same − Input Suppose our given input is − MyVal = [34, 67, 2, 45, 8, 12] Output The desired output would be − Geometric ... Read More

Swift Program to Find Harmonic Mean of the Numbers

Ankita Saini
Updated on 20-Oct-2022 08:13:24

208 Views

This tutorial will discuss how to write swift program to find the harmonic mean of the numbers. Harmonic mean also known as HM is defined as the reciprocal of the average of reciprocal. Or we can say that harmonic mean is the reciprocal of the arithmetic mean by their reciprocal. Suppose a1, a2, a3, a4, .....an are the n-elements of a collection then the harmonic means is − HM = n/[(1/a1) + 1/(a2) + 1/(a3) + 1/(a4)+...+ 1/(an)] Below is a demonstration of the same − Input Suppose our given input is − MyVal = [3.4, 1.2, 7.8, 4.5, 2.4] ... Read More

Swift Program to Find Median of an Unsorted Array

Ankita Saini
Updated on 20-Oct-2022 08:12:04

832 Views

This tutorial will discuss how to write swift program to find median of an unsorted array. An array is an ordered collection which is used to store same type of data. For example, if any array is of integer type then it will only store integers, you are strictly not allowed to store elements of other data types like string, float, etc. Syntax Following is the syntax for an array − var array1 = [val1, val2, val3, …] Or var array2 = [Type]() Median represent the middle value of the given sorted set of numbers. We can calculate the ... Read More

Swift Program to Find Mean of an Unsorted Array

Ankita Saini
Updated on 20-Oct-2022 08:10:18

180 Views

This tutorial will discuss how to write swift program to find mean of an unsorted array. An array is an ordered collection which is used to store same type of data. For example, if any array is of integer type then it will only store integers, you are strictly not allowed to store elements of other data types like string, float, etc. Syntax Following is the syntax for an array − var array1 = [val1, val2, val3, …] Or var array2 = [Type]() Mean represent the average of the given numbers. It is calculated by dividing the sum of ... Read More

Advertisements