Akhil Sharma

Akhil Sharma

507 Articles Published

Articles by Akhil Sharma

Page 44 of 51

Golang program to add elements to a slice

Akhil Sharma
Akhil Sharma
Updated on 17-Jan-2023 1K+ Views

In this tutorial, we will learn how to add elements to a slice using different examples. A slice is a sequence of elements just like an array. An array is a fixed sequence of elements whereas slice is a dynamic array which means 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 go through the example to understand things. Method 1: Using append function with strings In this method, we will use append function to add string elements to the slice. ...

Read More

Golang Program To Push An Array Into Another Array

Akhil Sharma
Akhil Sharma
Updated on 10-Jan-2023 4K+ Views

In this tutorial, we will write a go language program to push an array to another array. There are many methods for this. The simplest one is to use equality operator. Here, we will see 3 methods via which we can transfer the contents of one array to another in go programming language. Method 1: Push an Array of Strings to an Empty Array by using Equality Operator In this method, we will use equality operator to add the contents of one array to another in the main() section of the program. Note that while transferring elements via this method ...

Read More

Golang Program To Get The Last Given Number Of Items From The Array

Akhil Sharma
Akhil Sharma
Updated on 10-Jan-2023 253 Views

In this tutorial, we will write a go language program to remove 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. Method 1: Remove the Last given Number of Items from an Array of Integers using Append() In this method, we will write a go language program to remove the last given number of items from an array by using the ...

Read More

Golang Program To Get The First Item From The Array

Akhil Sharma
Akhil Sharma
Updated on 10-Jan-2023 3K+ Views

In this tutorial, we will write a go language program to get the first item from an array. An array is a data structure that is used to store elements in contiguous memory locations. Here, 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 First Item from the Array using Append() Function In this method, we will write a golang program to get the first element ...

Read More

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

Akhil Sharma
Akhil Sharma
Updated on 10-Jan-2023 1K+ 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
Akhil Sharma
Updated on 10-Jan-2023 261 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
Akhil Sharma
Updated on 10-Jan-2023 2K+ 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
Akhil Sharma
Updated on 10-Jan-2023 13K+ 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
Akhil Sharma
Updated on 10-Jan-2023 15K+ 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 Calculate Average Using Arrays

Akhil Sharma
Akhil Sharma
Updated on 06-Jan-2023 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
Showing 431–440 of 507 articles
« Prev 1 42 43 44 45 46 51 Next »
Advertisements