Found 26504 Articles for Server Side Programming

Swift program to Print an Identity Matrix

Ankita Saini
Updated on 09-Jan-2023 15:11:52

227 Views

In this article, we will learn how to write a swift program to print an identity matrix. Identity matrix is a square matrix in which the main diagonal elements contain only one and the rest of the elements are 0. For example − $\mathrm{Matrix\:=\:\begin{bmatrix}1 & 0 & 0 & 0 & 0 ewline0 & 1 & 0 & 0 & 0 ewline0 & 0 & 1 & 0 & 0ewline0 & 0 & 0 & 1 & 0ewline0 & 0 & 0 & 0 & 1\end{bmatrix}}$ Algorithm Step 1 − Create a function. Step 2 − In this function, use ... Read More

Swift Program to Multiply two Matrices by Passing Matrix to a Function

Ankita Saini
Updated on 09-Jan-2023 15:07:43

226 Views

In this article, we will learn how to write a swift program to multiply two matrices by passing the matrix to a function. A matrix is a mathematical structure in which the elements are present in rows and columns format. For example, the first element is present at the a00 location, the second at a01, and so on. So to multiply two matrices, we multiply the mth row of the first matrix by an nth column of the second matrix and add the products. This will create an element at the mth row and nth columns of the resultant matrix. ... Read More

Swift Program to Multiply two Matrices Using Multi-dimensional Arrays

Ankita Saini
Updated on 09-Jan-2023 15:06:24

801 Views

In this article, we will learn how to write a swift program to multiply two matrices using multi-dimensional arrays. A matrix is a mathematical structure in which the elements are present in rows and columns format. For example, the first element is present at the a00 location, the second at a01, and so on. Therefore, to multiply two matrices, we multiply the mth row of the first matrix by an nth column of the second matrix and add the products. This will create an element at the mth row and nth columns of the resultant matrix. For example − ... Read More

Swift Program to initialize and print a complex number

Ankita Saini
Updated on 09-Jan-2023 14:53:57

294 Views

In this article, we will learn how to write a swift program to initialize and print complex numbers. Complex numbers are those numbers which express in the form of x+yi, where x and y are real numbers and ‘i’ is an imaginary number known as iota. Alternatively, we can say that a complex number is a combination of both real and imaginary numbers. For example 1+2i, 1-3i, etc. In Swift, we use a struct to create complex numbers. Algorithm Step 1 − Create a structure using the struct keyword. Step 2 − In this structure, create two properties ... Read More

Swift Program to get the real part from a Complex number

Ankita Saini
Updated on 09-Jan-2023 14:51:57

163 Views

In this article, we will learn how to write a swift program to get the real part from the complex number. Complex numbers are those numbers which express in the form of x+yi, where x and y are real numbers and ‘i’ is an imaginary number known as iota. For example, 2+2i, 1-3i, etc. where 2 and 1 are the real part and 2i and -3i is the imaginary part. Here we use the following methods to get the real part − Using the function Without using the function Method 1: Using the function To get the real ... Read More

Swift Program to get the numerator from a rational number

Ankita Saini
Updated on 09-Jan-2023 14:50:41

189 Views

In this article, we will learn how to write a swift program to get the numerator from a rational number. A rational number is a number which represents in the form of n/m where m is not equal to zero. Here n is known as the numerator and m is known as the denominator. For example, 7/9, 13/23, etc. Here, 7 and 13 are numerators whereas 9 and 23 are denominators. Algorithm Step 1 − Create a structure to create a rational number. Step 2 − In this structure, create two properties of integer type to store the numerator and ... Read More

Swift Program to get the imaginary part of the given complex number

Ankita Saini
Updated on 09-Jan-2023 14:48:54

156 Views

In this article, we will learn how to write a swift program to get the imaginary part of the given complex number. Complex numbers are those number which express in the form of x+yi, where x and y are real numbers and ‘i’ is an imaginary number known as iota. For example: 1+2i, 1-3i, etc. Here we use the following methods to get imaginary part − Using function Without using function Method 1: Using function To get the imaginary part of the complex number we create a function which takes struct object as a parameter and return the ... Read More

Swift Program to get the denominator from a rational number

Ankita Saini
Updated on 09-Jan-2023 14:46:37

305 Views

In this article, we will learn how to write a swift program to get the denominator from the rational number. A rational number is a number, which represents in the form of n/m where m is not equal to zero. Here n is known as the numerator and m is known as the denominator. For example, 2/3, 11/19, etc. Here, 2 and 11 are numerators whereas 3 and 19 are denominators. Algorithm Step 1 − Create a structure to create a rational number. Step 2 − In this structure, create two properties of integer type to store the numerator and ... Read More

Swift Program to Copy All the Elements of One Array to Another Array

Ankita Saini
Updated on 09-Jan-2023 14:44:28

4K+ Views

In this article, we will learn how to write a swift program to copy all the elements of one array to another array. Swift doesn’t provide a direct method to copy the elements of one array to another but we can do this using the following methods − Using map(_:) method Using = operator Using append(contentsOf:) method Method 1: Using map(_:) method The map(_:) method is used to return an array that contains the result of mapping the given closure over the specified sequence’s elements. Syntax func map(_mclosure:(Self.Element) throws - >T)rethrows [T] Here, mclouser is a mapping ... Read More

Swift Program to Check If a Number is Spy number or not

Ankita Saini
Updated on 09-Jan-2023 14:40:19

589 Views

In this article, we will learn how to write a swift program to check if a number is a spy number or not. A spy number is a number in which the sum of the digits of the given number is equal to the product of the digits of the given number. For example − Number = 123 Sum = 1 + 2 + 3 = 6 Product = 1 * 2 * 3 = 6 Hence 123 is a spy number because sum = product Number = 23 Sum = 2 + 3 = 5 Product = 2 * ... Read More

Advertisements