Found 1082 Articles for Go Programming

Golang Program To Remove The First Given Number Of Items From The Array

Akhil Sharma
Updated on 10-Jan-2023 14:53:02

769 Views

In this tutorial, we will write a go language program to remove the first given number of items from an array. We can do this by either using the inbuilt functions in go or using the for loops. The first method is more efficient in functionality than the second one but we will discuss both these methods in this program. Method 1: Remove the First given Number of Items from an Array of Integers using Internal Functions In this method, we will write a go language program to remove the first given number of items from an array by using ... Read More

Golang Program To Determine If a Given Matrix is a Sparse Matrix

Akhil Sharma
Updated on 10-Jan-2023 14:50:29

142 Views

In this tutorial, we will write a go language program to determine whether a given matrix is sparce or not. A square matrix is called a sparse matrix if the number of zeroes present in the matrix are more than the non-zero elements in the matrix. Golang Program to Check if a Matrix is Sparce In this example, we will write a Golang program to check the sparce matrix. We will use for loops along with if conditions to achieve the result in the main section of the program. Algorithm Step 1 − First, we need to import the fmt ... Read More

Golang Program To Get The Last Item From The Array

Akhil Sharma
Updated on 10-Jan-2023 14:47:59

1K+ Views

In this tutorial, we will write a go language program to get the last item from an array. An array is a data structure that is used to store elements in contiguous memory locations. In this article, we will write two programs to store the first element in the array. In the first program, we will use the concept of indexing and in the second we will use the for loops to get the required result. Method 1: Get the Last Item from the Array of Integers in the Main In this method, we will write a golang program ... Read More

Golang Program to Calculate Difference Between Two Time Periods

Akhil Sharma
Updated on 10-Jan-2023 14:46:04

9K+ Views

In this tutorial, we will write a golang programs to calculate the difference between two time periods given in the following programs. To get the time difference between two time periods we can either use a library function or can create a separate user-defined function to achieve the results. Method 1: Calculate the Difference between Two Time Periods using Internal Function In this method, we will write a go language program to find the difference between time periods using pre-defined functions in go programming language. Syntax func (t Time) Sub(u Time) Duration The sub() function in go is ... Read More

Golang Program To Append An Element Into An Array

Akhil Sharma
Updated on 10-Jan-2023 14:43:24

11K+ Views

In this tutorial, we will write a go language program to iterate over an array. An array is a data structure, which is used to store data at contiguous memory locations. There are many methods to append an element in an array. We shall discuss them in this program Example 1: Add Values to an Array of Strings in the Main() Function In this example, we will write a go language program to add values to an array of strings in the main() function. We will first initialize an array of strings of specific size and then add values ... Read More

Golang Program To Convert An Array Into A String And Join Elements With A Specified Character

Akhil Sharma
Updated on 10-Jan-2023 14:41:13

6K+ Views

In this tutorial, we will write a go language program to convert an array to a string and separate them by a specified character. Arrays are data structures that are used to store values at contiguous memory locations. Method 1: Convert an Array into a String using Join() Function In this method, we will write a golang program to convert an array to a string using a library function. We will make a separate function, which will accept the array to be converted as an argument, and convert it to the string, and returns the result. Syntax func ... Read More

Golang Program to Remove Repeated Elements From an Array

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

345 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

1K+ 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

397 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

1K+ 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