Akhil Sharma

Akhil Sharma

507 Articles Published

Articles by Akhil Sharma

Page 38 of 51

Golang Program to remove given element from the array

Akhil Sharma
Akhil Sharma
Updated on 13-Feb-2023 4K+ Views

In this tutorial, we will learn how to remove an element from an array using simple for loop approach. The logic behind this approach is that create a new array and the particular index element which is to be removed don’t add it to the new array. Let’s have a look how to execute it with the use of different examples. Remove Element from the Array in main Function In this method, we will execute the entire program inside main function. An original array and a new array will be created to execute the removal of elements from the array. ...

Read More

Golang program to illustrate the creation of strings

Akhil Sharma
Akhil Sharma
Updated on 13-Feb-2023 205 Views

In this tutorial, we will see how strings are created in Golang. There are different ways to create strings which we will learn via some examples. In Golang a string is a sequence of variable-width characters where each character is represented by one or more bytes. Method 1: Using double Quotes with Shorthand Declaration In this method, we will learn about how to create strings using shorthand declaration. Let’s dive into the code to understand it. Algorithm Step 1 − Create a package main and import fmt package in the program. Step 2 − Create a function main and further ...

Read More

Golang Program to search an item into the array using interpolation search

Akhil Sharma
Akhil Sharma
Updated on 13-Feb-2023 317 Views

In this tutorial, we will see how to search an item in the array using interpolation search. It is very similar to Binary search but is an improved version of it, in this algorithm the element is searched from the sorted array using a different method to find middle element and the output is printed using print function in Golang. Let’s have a look to understand it − Using interpolation search in main method In this method, we will learn how to search an element in the array using an interpolation search method. All the things will be executed in ...

Read More

Golang Program to print a hollow star triangle pattern

Akhil Sharma
Akhil Sharma
Updated on 10-Feb-2023 340 Views

In this tutorial, we will learn how to print hollow star triangle pattern using Go programming language. The user can specify the maximum number of rows to print as an inverted pyramid star pattern using this GO programmed. Here, we'll print the inverted Pyramid of * symbols up till the user-specified rows are reached. Algorithm STEP 1 − Import the package fmt STEP 2 − Start function main() STEP 3 − Declare and initialize the variables and assign value to them. STEP 4 − Initialize a variable to store the number of rows that star pattern should print. STEP 5 ...

Read More

Golang Program to Create an enum class

Akhil Sharma
Akhil Sharma
Updated on 10-Feb-2023 538 Views

An enum combines related constants into a single type. Enums are a strong feature with many applications. However, compared to the majority of other programming languages, they are implemented very differently in Go. In this article, we'll see how to use a predeclared identifiable iota to implement enums in Golang. IOTA − Iota is an identifier that is used with constants and can make auto-increment number-based constant definitions simpler. The keyword "iota" stands for an integer constant that begins at zero. Implementing Iota package main import "fmt" const ( c0 = iota + 1 ...

Read More

Golang Program to get the flattened 1D array

Akhil Sharma
Akhil Sharma
Updated on 10-Feb-2023 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
Akhil Sharma
Updated on 10-Feb-2023 250 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
Akhil Sharma
Updated on 10-Feb-2023 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
Akhil Sharma
Updated on 10-Feb-2023 7K+ 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
Akhil Sharma
Updated on 10-Feb-2023 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
Showing 371–380 of 507 articles
« Prev 1 36 37 38 39 40 51 Next »
Advertisements