Found 33676 Articles for Programming

Golang Program to check the given string is empty or not

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

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

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

394 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

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

808 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

Golang program to calculate the symmetric difference between two slices

Akhil Sharma
Updated on 24-Jul-2023 12:21:40

524 Views

Slice is similar to an array, the only difference is that an array is a fixed sequence of elements whereas slice the array elements are dynamic. This makes the slice more efficient and faster in various applications. In the slice, the elements are passed by reference instead of values. In this article, we are going to learn about different techniques to calculate the symmetric difference between two slice using Golang programming. 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 shuffle the elements of an array

Akhil Sharma
Updated on 13-Feb-2023 16:14:16

982 Views

An array is a fixed sequence of elements in which the elements are placed at contiguous memory locations. We will shuffle and randomly place the elements of the array. In the first case we will use fisher-yates shuffle algorithm. Let’s see how we can execute it using different logics in the Golang code. Syntax rand.Seed(value) Rand.Seed() function is used to generate random numbers. It takes a user input as argument which is the upper limit for generating random numbers. func Now() Time The Now() function is defined in time package. this function generates the current local time. to ... Read More

Golang Program to get the first given number of items from the array

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

180 Views

In this tutorial, we will write a go language program to get the first given number of items from an array. We can do this by either using the inbuilt functions in go or by 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: Getting items from an array of integers using internal functions In this method, we will write a go language program to get the first given number of items from an array by using the append() library function. Syntax ... Read More

Golang program to compare two strings

Akhil Sharma
Updated on 13-Feb-2023 16:12:08

840 Views

In go programming language, string is one of the data-types that can be used for various application. It is a collection of characters and is also immutable. In go programming language a string can't be modified after they have been created. In this article, we are going to study different techniques to compare two given strings. Syntax bytes.Equal(s1, s2) Two slices of bytes ([]byte) are compared using the Equal() method to see if they are equal. If the two slices of bytes are equal, it produces a boolean result (true or false) reflecting that fact. strings.Compare(s1, s2) The ... Read More

Golang program to remove a subset from a slice

Akhil Sharma
Updated on 13-Feb-2023 16:11:33

519 Views

Slice is similar to an array, the only difference is that an array is a fixed sequence of elements whereas slice the array elements are dynamic. This makes the slice more efficient and faster in various applications. In slice, the elements are passed by reference instead of values. In this article, we will learn different techniques to remove a subset from slice using go language programming 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 ... Read More

Advertisements