Found 1082 Articles for Go Programming

Golang Program to Display Factors of a Number

Akhil Sharma
Updated on 29-Dec-2022 12:25:10

579 Views

In this tutorial program, we will learn how to display the factors of a given number in the Go programming language. A factor of a number is defined as the algebraic expression that divides any given number evenly, with its remainder being zero. All composite numbers will have more than two factors, that include 1 and the number itself also. For example: by multiplying 3 and 7, we get 21. We say 3 and 7 are factors of 21. Below is a demonstration of the same − Input Suppose our input is = 15 Output The factors of 15 ... Read More

Golang Program to Convert String Value to Byte Value

Akhil Sharma
Updated on 07-Oct-2023 01:11:06

29K+ Views

In this tutorial, we will learn how to convert string values to byte values using golang programming language. String Value − A string value is just a sequence of characters, like "abc". A string value is always enclosed in quotes. All types of characters are allowed (even digits, as in "abc123"). Strings can contain any number of characters. Byte value − The byte data type is an 8-bit signed two's complement integer. It has a minimum value of -128 and a maximum value of 127 (inclusive). The byte data type can be useful for saving memory in large arrays, where ... Read More

Golang Program to Convert Char Type Variables to Int Using Inbuilt Functions

Akhil Sharma
Updated on 29-Dec-2022 12:18:04

3K+ Views

In this tutorial, we will learn how to convert character type to integer type variable using Golang programming language. In the Go programming language, there is no char data type. It uses bytes and rune and strings to represent character values. Example-1: Golang Program Code to Convert Char to Int Using Atoi() Function Syntax func Atoi(str string) (int, error) Here, str is the string. Atoi() function is equivalent to ParseInt(str string, base int, bitSize int) is used to convert string type into int type and to access Atoi() function you need to import strconv Package in your program. Algorithm ... Read More

Golang Program To Convert Array To Set

Akhil Sharma
Updated on 29-Dec-2022 12:15:18

3K+ Views

In this tutorial, we will learn how to convert an array to a set using the Golang programming language. A Set is a collection of items. You can iterate on these items / add new / remove items and clear the set and get the size and check if the set contains any value. An object in the set might only be stored once and cannot duplicate. Syntax var myset map[type]struct{} Key is a type of data you want to create. Struct{} is an empty struct that takes 0 bytes in size. Example 1: Go Code to Convert an ... Read More

Golang Program to Show Encapsulation in Class

Akhil Sharma
Updated on 29-Dec-2022 12:12:43

347 Views

In this article, we are going to learn about Encapsulation in class using Golang Program Encapsulation in go Language vs Other Object-Oriented Languages − The variables or data of a class in object-oriented languages are private to that class and can only be accessed through any member functions of the class in which they are specified. However, classes and objects are not supported by the Go language. So using packages to accomplish encapsulation in the Go programming language. Go offers exported and unexported identifiers, two separate forms of identifiers. Exporting variables, functions, methods, fields, and structures from the packages enables ... Read More

Golang Program To Convert Set Of String To Array Of String

Akhil Sharma
Updated on 28-Dec-2022 17:03:22

2K+ Views

In this tutorial, we will write a golang program to convert a set of strings to array of strings. In go a set is an abstract data type that can store specific values without repeating any of them and without any particular sequence. Convert Set Of String To Array Of Strings Using Internal Functions The program to convert a set of strings to array of strings using predefined functions in go programming language is given below. Syntax func make([]type, length, capacity) []type The make function is used to make a slice or map. It takes three arguments one is ... Read More

Golang Program to Convert List to Set

Akhil Sharma
Updated on 28-Dec-2022 16:42:50

585 Views

In this tutorial, we will write a golang program to convert a list to set. A linked list is a structure that is created dynamically it has two elements one to store the value and other to store the address of the next structure. A set is an abstract data type that can store specific values without repeating any of them and without any particular sequence. Convert a Linked List to a Set Now let us look at an example to convert the linked list to a set. Syntax func make([]type, length, capacity) []type The make function is used ... Read More

Golang Program to Convert List to Map

Akhil Sharma
Updated on 28-Dec-2022 16:40:16

950 Views

In this tutorial, we will write a golang program to convert a list to map. A linked list is a structure that is created dynamically it has two elements one to store the value and other to store the address of the next structure. A map store element in key:value pairs. A map is an unsorted, flexible collection that forbids duplications. Convert A List to Map In this article, we will discuss to convert a linked list to map. The following program illustrates this conversion process. Syntax func make([]type, length, capacity) []type The make function is used to make ... Read More

Golang Program to Compute the Sum of Diagonals of a Matrix

Akhil Sharma
Updated on 28-Dec-2022 16:37:38

443 Views

In this tutorial, we will write a go language program to find the sum of diagonal elements of a matrix. Compute the Sum of Diagonals of a Matrix In this example, we will find the sum of left diagonal elements of a 3 x 3 matrix using external function. Algorithm Step 1 − Import the fmt package. Step 2 − Create a function to find the sum of the given matrix. Step 3 − In this function initialize an integer variable named sum and use a for loop to intend over the matrix array. Step 4 − ... Read More

Golang Program to Check Whether Two Matrices are Equal or Not

Akhil Sharma
Updated on 28-Dec-2022 16:35:03

170 Views

In this tutorial, we will write a golang program to check whether two matrices are equal or not. A matrix is a collection of numbers arranged in rows and columns, a two-dimensional array. Check Whether Two Matrices are Equal or Not using If Statment In this example we will compare the equality of two matrices using if condition statements. Algorithm Step 1 − Import the fmt package. Step 2 − Start the main() function. Step 3 − Initialize and assign values the two matrices. Step 4 − Print these matrices on the screen. Step 5 − Now use the equality(==) ... Read More

Advertisements