Programming Articles - Page 504 of 3366

Swift Program to get the numerator from a rational number

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

197 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

163 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

314 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

597 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

Swift program to check if a given square matrix is an Identity Matrix

Ankita Saini
Updated on 09-Jan-2023 14:36:29

281 Views

In this article, we will learn how to write a swift program to check if a given square matrix is the identity matrix. The identity matrix is an MxM square matrix in which the main diagonal consists of ones and other elements are all zero. For example − $\mathrm{M\:=\:\begin{bmatrix}1 & 0 & 0 & 0ewline0 & 1 & 0 & 0 ewline0 & 0 & 1 & 0 ewline0 & 0 & 0 & 1\end{bmatrix}}$ Whereas a square matrix is a matrix in which the number of rows is equal to number of columns and it may or may not ... Read More

Golang Program to Remove Repeated Elements From an Array

Akhil Sharma
Updated on 06-Jan-2023 16:34:19

481 Views

In this tutorial, we will write a go language program to remove duplicate elements from an array. By removing the duplicate entries, we mean that we wish to remove a value repeating multiple times. In this tutorial, we are using examples of an array of integers as well as an array of strings. Method 1: Remove Duplicate Values from an Array using an External Function The following code illustrates how we can remove duplicate values from an array of integers using a user-defined function. Algorithm Step 1 − First, we need to import the fmt package. Step 2 − ... Read More

Golang Program to Calculate Average Using Arrays

Akhil Sharma
Updated on 06-Jan-2023 16:31:58

2K+ Views

In this tutorial, we will see to write a go language program to calculate the average of numbers using arrays. We are creating two programs in this example. In the first method, we are using a user-defined function to calculate the average while in the second one we are using an internal go function to find the same. Method 1: Calculate the Average of Numbers using Arrays In this method, we will create a separate function and pass the array to it. The function accepts the array as an argument and then after calculating the average it returns the ... Read More

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

Akhil Sharma
Updated on 06-Jan-2023 16:30:27

559 Views

In this tutorial, we will write a go language program to multiply two matrices by passing them to a function. In order to achieve this result, we will use both single dimension and multi-dimensional matrices. The difference between a single-dimension array and a multidimensional matrix is that the former has the same order while the latter has a different order of rows and columns. Method 1: Multiply Two Matrices of the Same Order by Passing them to a Function In this method, we will see to multiply two matrices of the same order bypassing the matrix to a user-defined function ... Read More

Golang Program to Multiply to Matrix Using Multi-Dimensional Arrays

Akhil Sharma
Updated on 06-Jan-2023 16:27:51

2K+ Views

In this tutorial, we will write a go language program to multiply two matrices. The difference between a single-dimensional array and a multi-dimensional array is that the former holds an attribute while the latter holds another array on the index. Additionally, every element of a multidimensional array will have the same data type. Method 1: Multiply Two Matrices using Multi-Dimensional Arrays in the Main Function In this method, we will write a golang program to multiply two Multi-dimensional matrices using for loops in the main() function. Algorithm Step 1 − Import the fmt package. Step 2 − Now, ... Read More

Advertisements