Found 1082 Articles for Go Programming

Golang Program to find the index of the first occurrence of the specified item in the array

Akhil Sharma
Updated on 09-Feb-2023 15:48:38

586 Views

In this article we will write a go language program to find the index of the first occurrence of the specified item in an array. we will use for loops and inbuilt go library functions to achieve the result. Method 1: Using SearchInts() Library Function Syntax func Sort(data Interface) The sort() function is present in sort package. this function is used to sort an array in ascending order. The array to be sorted is passed as an argument to the function. The time complexity of this function is O(n * logn). type IntSlice []int The IntSlice() function is ... Read More

Golang Program to insert multiple elements into the array from the specified index

Akhil Sharma
Updated on 09-Feb-2023 15:45:50

971 Views

In this tutorial, we will write a go language program to insert multiple elements into an array at the specified index. There are many methods to add elements into an array. it can be done by either using indexing or by using for loops. There are some inbuilt functions too using which we can add elements at specified index. 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

Golang Program to insert an element into the array at the specified index

Akhil Sharma
Updated on 09-Feb-2023 15:41:17

2K+ Views

In this tutorial, we will write a go language program to insert an element into an array at the specified index. There are many methods to add elements to an array. it can be done by either using indexing or by using for loops. There are some inbuilt functions too using which we can add elements at the specified indexes. 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) ... Read More

Golang Program to get a substring from the string

Akhil Sharma
Updated on 13-Feb-2023 16:24:19

6K+ Views

A substring in Go is a portion of a larger string. It is specified by providing a start index and a length, and it contains the characters of the original string starting at the start index and going up to the specified length. The characters in a substring are still a part of the original string and share the same memory. In Go, a string is a sequence of characters. It is an immutable data type, meaning that once a string is created, it cannot be modified. Strings are enclosed in double quotes ("") and can contain any combination of ... Read More

Golang Program to find the uncommon elements from two arrays

Akhil Sharma
Updated on 09-Feb-2023 15:39:05

290 Views

In this tutorial, we will see to write a go language program to find uncommon elements in two arrays. In this article we will write two programs. In the first program we will use the array of strings while in the second one we will use the array of integers. Algorithm STEP 1 − import the fmt package. STEP 2 − Define three functions named intersection(), uniquearr1 and uniquearr2. STEP 3 − The intersection() finds the common array elements from the two arrays while the other two functions remove that common elements from given arrays. STEP 4 − All these ... Read More

Golang Program to check the given string is empty or not

Akhil Sharma
Updated on 13-Feb-2023 16:22:52

963 Views

In Go, a string is a sequence of characters. It is an immutable data type, meaning that once a string is created, it cannot be modified. Strings are enclosed in double quotes ("") and can contain any combination of letters, numbers, and symbols. They are commonly used to store text and are often used as input and output in programs. Syntax func len(v Type) int The len() function is used to get the length of a any parameter. It takes one parameter as the data type variable whose length we wish to find and returns the integer value ... Read More

Golang Program to reverse the elements of the array using inbuilt function

Akhil Sharma
Updated on 09-Feb-2023 15:34:11

930 Views

In this tutorial, we will write a go language program to reverse the elements of the array using inbuilt functions. in this program we will see how we can reverse an array of strings and integers using internal go functions. Method 1: Using Append() and Make() 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 func append(slice, element_1, element_2…, element_N) []T The append function is used to add values to an array ... Read More

Golang Program to convert Binary to Octal

Akhil Sharma
Updated on 09-Feb-2023 15:28:42

218 Views

In this article you will learn the go language code to convert binary number to octal number. Binary numbers are the numbers that have base 2, i.e., each digit can have only 2 possibilities 0 and 1. Octal numbers are the numbers that have base 8, i.e., each digit can have only 8 possibilities from 0 to 7. Algorithm STEP 1 − Import the fmt package. STEP 2 − Start the main function and initialize the required variables of type int naming binary, octal, remainder and j. store initial values to them. STEP 3 − Store the binary number chosen ... Read More

Golang Program to find the common elements from two arrays

Akhil Sharma
Updated on 09-Feb-2023 15:16:14

868 Views

In this tutorial, we will see to write a go language program to find common elements in two arrays. In this article we will write two programs. in the first program we will use the array of strings while in the second one we will use the array of integers. Method 1: Using Append() Function The following code illustrates how we can find the common elements in two different arrays of strings using an external function in go programming language. The function which we will create takes the two arrays as an argument to it and returns the final array ... Read More

Golang program to find all subsets of a string

Akhil Sharma
Updated on 13-Feb-2023 16:21:25

541 Views

A string in Golang is a collection of characters. Since strings in Go are immutable, they cannot be modified after they have been produced. Concatenating or adding to an existing string, however, enables the creation of new strings. A built-in type in Go, the string type can be used in a variety of ways much like any other data type. Algorithm Step 1 − Create a package main and declare fmt(format package) and sort package in the program where main produces executable codes and fmt helps in formatting input and output. Step 2 − Create a main function and ... Read More

Advertisements