Found 1082 Articles for Go Programming

Golang Program To Sort An Array In Ascending Order Using Insertion Sort

Akhil Sharma
Updated on 06-Jan-2023 16:24:53

458 Views

Insertion sort is defined as an In-Place Algorithm and it is declared as a stable algorithm. The idea of sorting an array in ascending or descending order by swapping an element can be used to implement Insertion Sort. For instance, if the array contains only one item in the list, then it is considered sorted. Otherwise, we consider that a certain portion of the list of elements is sorted while other is unsorted. Proceeding with this assumption, we traverse through the unsorted list, picking one element at a time. Syntax rand.Seed(value) Rand.Seed() function is used to generate random ... Read More

Golang Program To Iterate Over Each Element From The Arrays

Akhil Sharma
Updated on 06-Jan-2023 16:21:13

727 Views

In this tutorial, we will write a go language program to iterate over each element of the array. An array is a data structure that is used to store data at contiguous memory locations. There are many methods to iterate over an array. The simplest one is to use a for loop. Here, we will see how we can iterate over the integer and string types of arrays using various methods in go. Method 1: Iterate over the Array using For Loop In this method, we will write a go language program to iterate over the array using for loops. ... Read More

Golang Program To Find The Transpose Of A Matrix

Akhil Sharma
Updated on 06-Jan-2023 16:18:57

583 Views

In this article, we will write a go language program to find the transpose of a matrix. A matrix is a collection of numbers arranged in rows and columns, a two-dimensional array. Transpose of a matrix is defined as a matrix obtained by interchanging the rows and columns of that matrix. Method 1: Find the Transpose of a Matrix using For Loop In this example, we will write a go language program to find the transpose of the matrix using for loops in the main function. Algorithm Step 1 − Import the fmt package. Step 2 − Call the main() ... Read More

Golang Program To Display Upper Triangular Matrix

Akhil Sharma
Updated on 06-Jan-2023 16:15:37

209 Views

In this article, we will write a go language program to print the upper triangular matrix of any given matrix. Introduction − A square matrix is called an upper triangular matrix if it has zero values below the principal diagonal. A matrix is displayed in its upper triangular form only if it is square. i.e. it must have the same number of rows and columns. The order of a typical upper triangular matrix is N X N. Method 1: Display Upper Triangular Matrix using For Loops In this method, we will write a go language program to display upper ... Read More

Golang Program To Remove Duplicates From An Array

Akhil Sharma
Updated on 06-Jan-2023 16:10:26

4K+ Views

In this article, we will write a go language program to remove duplicates from an array. To achieve this we will be using two approaches. In the first one, we will use the array of strings, and in the second one; we will be using an array of integers. Method 1: Remove Duplicates from an Array of Strings using The Make() Function In this example, we will write a go language program to remove duplicates from the array of strings using a user-defined function. The function will accept the array of strings as an argument and will return the final ... Read More

Golang Program To Sort The Elements Of An Array In Descending Order

Akhil Sharma
Updated on 02-Jan-2023 15:30:40

458 Views

In this tutorial, we will see to write a go language program to sort an array in descending order. In mathematics, a descending order is an order in which the following element is smaller than the previous element. To Sort An Array In Descending Order Using External Functions In this example, we will see to write a program to sort an array of integers in descending order using user defined function. Algorithm Step 1 − Import the fmt package Step 2 − Define a function sortDesc() to sort the given array. This function accepts one argument as the array ... Read More

Golang Program To Sort The Elements Of An Array In Ascending Order

Akhil Sharma
Updated on 02-Jan-2023 15:29:08

2K+ Views

In this tutorial, we will see to write a go language program to sort an array in ascending order. Sort An Array In Ascending Order Using A User-Defined Function The following code illustrates how we can sort an array of elements in ascending order in golang. Algorithm Step 1 − Import the fmt package. Step 2 − Define a function sortArray() to sort the given array. Step 3 − Pass arguments to sortArray() function one is the array of integers that we wish to sort and the other two variables are used to hold temporary values. Step ... Read More

Golang Program To Sort An Array

Akhil Sharma
Updated on 02-Jan-2023 15:27:39

4K+ Views

In this tutorial, we will see to write a go language program to sort an array using three different methods. Sort An Array Of Integers Using User-Defined Functions The following code illustrates how we can sort an array of elements in golang using user-defined functions. Algorithm Step 1 − Importing the fmt package. Step 2 − Defining a function named sortArray() which will sort the given array. Step 3 − Pass the array to be sorted as an argument to this function. This function uses two for loops to iterate over the array. Step 4 − If ... Read More

Golang Program To Rotate Matrix Elements

Akhil Sharma
Updated on 02-Jan-2023 15:25:54

568 Views

In this article, we will write a go language program to rotate given matrix element. Rotate A Matrix Using An External Function The following code illustrates rotating a matrix anticlockwise by 90 degrees any number of times. Algorithm Step 1 − Import the fmt package. Step 2 − Create a function to rotate the array elements. This function takes the array to be rotated as argument. Step 3 − Also pass the number of times the array is to be shifted as argument. Further, initialize an empty matrix to hold the final result. Step 4 − In ... Read More

Golang Program To Remove Duplicate Elements From An Array

Akhil Sharma
Updated on 02-Jan-2023 15:24:08

411 Views

In this tutorial, we will see to write a go language program to remove duplicate elements from an array. By removing duplicate entries, we mean that we wish to write a program that will remove a value repeating multiple times. Remove Duplicate Values From An Array Using An External Function The following code illustrates how we can remove duplicate values from an array using a user-defined function. Algorithm Step 1 − First, we need to import the fmt package. Step 2 − Now, make a function named removeDuplicate() that accepts an array as an argument and returns an array ... Read More

Advertisements