Found 1082 Articles for Go Programming

Golang Program to compare strings using library function

Akhil Sharma
Updated on 10-Feb-2023 18:08:18

583 Views

In this article we will write an article to compare numbers and strings using library function in Go language. we will write two programs to illustrate. In the first program we will use the external user defined function and in the second one we will use the internal library function to implement the logic. Syntax func Compare(s1, s2 string) int Compare() function is used to compare the given strings in go. It is present in strings package. This function takes the strings to be compared as argument to the function and returns the integer equivalent after comparing the two ... Read More

Golang Program to convert boolean variables into string

Akhil Sharma
Updated on 10-Feb-2023 17:02:45

350 Views

In this tutorial, we will learn how to convert Boolean to a string in Go programming language. Boolean is a data type having 1 byte size. It can store any one of the three values mainly True, False or none. String data type is used to store a sequence of characters. Convert Boolean Variables to String using FormatBool() Functions Syntax func FormatBool(b bool) string This function is present in strconv package. FormatBool() function is used to convert a Boolean variable to string. The function takes the Boolean value as an argument and returns a string. Algorithm STEP 1 − ... Read More

Golang Program to print a hollow star triangle pattern

Akhil Sharma
Updated on 10-Feb-2023 17:00:25

215 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
Updated on 10-Feb-2023 16:58:57

380 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 Find the Largest Element in an Array

Akhil Sharma
Updated on 10-Feb-2023 16:57:03

2K+ Views

In this tutorial, we will see to write a go language program to search the largest element in an array. an array is a variable that is used to store elements at contiguous memory locations. We can find the largest element of an array by either using a separate function or by using for loop and if conditions in the main() function. Finding the Largest Element in an Array in Main Function() The following code illustrates how we can search and find the largest element present in an array. Algorithm STEP 1 − Import the fmt package that allows us ... Read More

Golang Program to Rotate Elements of an Array

Akhil Sharma
Updated on 10-Feb-2023 16:54:56

432 Views

In this tutorial, we will see to write a go language program to rotate an array. We will write two programs for this. One to rotate the array to left and another to rotate it to right. Algorithm STEP 1 − Import the fmt package that allows us to print anything on the screen. STEP 2 − Create a function named rotateLeft() which returns the final array after rotating it. STEP 3 − This function uses a for loop to iterate over the array and calls rotateLeftByOne() function in each iteration. STEP 4 − This function takes the array as ... Read More

Golang Program to get the flattened 1D array

Akhil Sharma
Updated on 10-Feb-2023 16:53:11

966 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
Updated on 10-Feb-2023 16:51:59

119 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
Updated on 10-Feb-2023 16:49:34

1K+ 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
Updated on 10-Feb-2023 16:47:35

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

Advertisements