Programming Articles - Page 471 of 3363

Golang Program to get the flattened 1D array

Akhil Sharma
Updated on 10-Feb-2023 16:53:11

1K+ Views

In this tutorial, we will write a go language program to get the flattened 1D array from a multidimensional 2D array. A multi-dimensional array is an array of arrays, where each inner array represents a row of elements. A 1D array, on the other hand, is a single array that contains all the elements of the multi-dimensional array in a contiguous manner. Syntax func append(slice, element_1, element_2…, element_N) []T The append function is used to add values to an array slice. It takes number of arguments. The first argument is the array to which we wish to add the ... Read More

Golang Program To Find the Trace and Normal of a given Matrix

Akhil Sharma
Updated on 10-Feb-2023 16:51:59

233 Views

In this tutorial we will write an article to find the normal and trace of a matrix. A matrix is considered to be normal if its square root equals the sum of the squares of each member and trace is the total of a matrix's diagonal elements. Finding Normal of the given Matrix Algorithm STEP 1 − First we need to import the fmt and math package. STEP 2 − Create a function to find the Normal of the matrix. This function uses two for loops to find the square of each element. STEP 3 − Update the sum variable ... Read More

Golang Program to get the subarray from an array using a specified range of indices

Akhil Sharma
Updated on 10-Feb-2023 16:49:34

2K+ Views

In this tutorial, we will write a go language program to get the sub array from an array using a specified range of indices. A subarray is a contiguous portion of an array, specified by a range of indices. For example, given the array [1, 2, 3, 4, 5] and the range of indices [1, 3], the resulting subarray would be [2, 3, 4]. Syntax func make ([] type, size, capacity) The make function in go language is used to create an array/map it accepts the type of variable to be created, its size and capacity as arguments func ... Read More

Golang Program to add an element in the array at the beginning

Akhil Sharma
Updated on 10-Feb-2023 16:47:35

6K+ Views

In this tutorial, we will write a go language program to add an element in the array at the beginning of an array. to add an element in the starting of an array we will use for loops and the concept of indexing in arrays. We shall now discuss these methods one by one in this program. Method 1: Using Append() Function Syntax func make ([] type, size, capacity) The make function in go language is used to create an array/map it accepts the type of variable to be created, its size and capacity as arguments and returns the ... Read More

Golang Program to get array elements after N elements

Akhil Sharma
Updated on 10-Feb-2023 16:42:39

1K+ Views

In this tutorial, we will write a go language program to get the last given number of items from an array. We can do this by either using the inbuilt functions in go or using for loops. The first method is more efficient in functionality than the second one but we will discuss both these methods in this program. Syntax func make ([] type, size, capacity) The make function in go language is used to create an array/map it accepts the type of variable to be created, its size and capacity as arguments func append(slice, element_1, element_2…, element_N) []T ... Read More

Swift Program to print the right diagonal matrix

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

670 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. For example 3x3, 5x5, 7x7, etc. In this article, we will learn how to write a swift program to print the right diagonal matrix. Algorithm Step 1 − Create a function. Step 2 − Run for-in loop to iterate through each element of the matrix. Step 3 − Check for ... Read More

Swift Program to print the left diagonal matrix

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

516 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 of square matrix. Square matrix is a matrix in which the number of rows and columns are same. For example 3x3, 5x5, 7x7, etc. Algorithm Step 1 − Create a function. Step 2 − Run for-in loop to iterate through each element of the matrix. Step 3 − Check ... Read More

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

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

1K+ 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 cube. In this article, we will learn how to write a swift program to check whether a number is a perfect cube or not. Method 1: Using user defined function To check if the given number is a perfect cube or not, we create a function that check each number ... Read More

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

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

586 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 divisors = 1, 2, 5 Hence, 10 is not a perfect number because the sum of its divisors is 8(1+2+5) In this article, we will learn how to write a swift program to check if the given number is a perfect number or not. Algorithm Step 1 − Create ... Read More

Swift Program to calculate the sum of rows of matrix elements

Ankita Saini
Updated on 16-Feb-2023 16:40:50

322 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.In this article, we will learn how to write a swift program to calculate the sum of rows of matrix elements. Here we are using the following methods to find the sum of the rows elements − Using nested for-in loop Using in-built function Method 1: Using nested for-in loop Here we use nested for-in loop to find the sum of rows of matrix elements. Algorithm Step 1 − Create a function. Step 2 ... Read More

Advertisements