Found 374 Articles for Go Programming

Golang program to get maximum and minimum from a slice

Akhil Sharma
Updated on 23-Jan-2023 15:00:51
In this article, we will see how to fetch maximum and minimum elements from a slice. A slice is a sequence of elements just like an array. An array is a fixed sequence of elements whereas a slice is a dynamic array, meaning its value is not fixed and can be changed. Slices are more efficient and faster than arrays moreover; they are passed by reference instead by value. Let us understand this basic concept using different set of examples and algorithms based upon them. Method 1: Using the Helper Function In this method, we will learn how to get ... Read More

Golang to check if a slice is empty

Akhil Sharma
Updated on 23-Jan-2023 14:58:50
In this article, we will check if the slice is empty or not using a variety of examples. A slice is a sequence of elements just like an array. An array is a fixed sequence of elements whereas a slice is a dynamic array, meaning its value is not fixed and can be changed. Slices are more efficient and faster than arrays moreover they are passed by reference instead by value. Let’s learn through examples how it can be executed. Syntax func append(slice, element_1, element_2…, element_N) []T The append function is used to add values to an array slice. ... Read More

Golang program to check if two slices are equal

Akhil Sharma
Updated on 23-Jan-2023 14:55:05
In this article, we will see what are the ways to check whether two slices are equal or not with the help of relevant examples. A slice is a sequence of elements just like an array. An array is a fixed sequence of elements whereas a slice is a dynamic array, meaning its value is not fixed and can be changed. Slices are more efficient and faster than arrays moreover; they are passed by reference instead by value. Let us learn the concept through examples. Method 1: Using a built-in Function In this method, we will use reflect.DeepEqual() function from ... Read More

Golang program to count the elements of a slice

Akhil Sharma
Updated on 23-Jan-2023 14:52:16
In this article, we will learn how to count the elements of a slice using a different set of examples. A slice is a sequence of elements just like an array. An array is a fixed sequence of elements whereas a slice is a dynamic array, meaning its value is not fixed and can be changed. Slices are more efficient and faster than arrays moreover; they are passed by reference instead by value. Let us learn through examples how it can be executed. Syntax func append(slice, element_1, element_2…, element_N) []T The append function is used to add values to ... Read More

Golang to remove null from a slice

Akhil Sharma
Updated on 23-Jan-2023 14:48:17
In this article, we will learn how to remove a null value from a slice using a variety of examples. A slice is a sequence of elements just like an array. An array is a fixed sequence of elements whereas a slice is a dynamic array, meaning its value is not fixed and can be changed. Slices are more efficient and faster than arrays moreover; they are passed by reference instead of value. Let us learn through examples how it can be executed. Method 1: Using For Loop In this method, we will see how to remove a null value ... Read More

Golang program to calculate the sum of right diagonal elements

Akhil Sharma
Updated on 23-Jan-2023 14:44:46
In this article, we will learn how to calculate the sum of right diagonal matrix with the help of different examples. A matrix is a 2-d array. The output will be printed on the screen using fmt.println() function which is a print statement in Golang. Algorithm Step 1 − Create a package main and declare fmt(format package) package in the program where main produces executable codes and fmt helps in formatting input and output. Step 2 − create a function main, in that function create a matrix, and fill with some values inside it. Step 3 − Print the ... Read More

Golang program to calculate the sum of left diagonal matrix

Akhil Sharma
Updated on 23-Jan-2023 14:41:36
In this article, we will learn how to calculate the sum of left diagonal matrix with the help of different examples. A matrix is a 2-d array. The left diagonal matrix is printed using the logic of indexes equal to each other. The output will be printed on the screen using fmt.println() function which is a print statement in Golang. Algorithm Step 1 − Create a package main and declare fmt(format package) package in the program where main produces executable codes and fmt helps in formatting input and output. Step 2 − Create a function main and in that ... Read More

Golang program to print the left diagonal matrix

Akhil Sharma
Updated on 23-Jan-2023 14:39:06
In this article, we will see how to print the left diagonal matrix with the help of suitable examples. A matrix is a 2-d array. Here in the examples, we will use a nested for loop which will iterate through the rows and columns of the matrix to print the left diagonal matrix. The output will be printed on the screen using fmt.println() function which is a print statement in Golang. Algorithm Step 1 − Create a package main and declare fmt(format package) package in the program where main produces executable codes and fmt helps in formatting input and ... Read More

Golang program to print right diagonal matrix

Akhil Sharma
Updated on 23-Jan-2023 14:36:40
In this article, we will see how to print the right diagonal matrix with the help of suitable examples. A matrix is a 2-d array. Here in the examples, we will use a nested for loop which will iterate through the rows and columns of the matrix to print the right diagonal matrix. The output will be printed on the screen using fmt.println() function which is a print statement in Golang. Algorithm Step 1 − Create a package main and declare fmt(format package) package in the program where main produces executable codes and fmt helps in formatting input and ... Read More

Golang program to initialize a slice

Akhil Sharma
Updated on 23-Jan-2023 14:34:56
In this article, we will learn how to initialize a slice using a variety of ways in examples. A slice is a sequence of elements just like an array. An array is a fixed sequence of elements whereas a slice is a dynamic array, meaning its value is not fixed and can be changed. Slices are more efficient and faster than arrays moreover they are passed by reference instead by value. Let’s learn through examples how it can be executed. Algorithm Step 1 − Create a package main and declare fmt(format package) package in the program where main produces ... Read More
1 2 3 4 5 6 7 ... 38 Next
Advertisements