Found 1082 Articles for Go Programming

Golang Program to get the numerator from a rational number

Akhil Sharma
Updated on 22-Dec-2022 18:31:40

204 Views

In this article, we will discuss how to get a numerator from a rational number. Syntax func NewRat(a, b int64) *Rat func (x *Rat) Num() *Int NewRat() function takes two integer numbers as input arguments and returns a rational number in the form of a/b. here a is the numerator and b is the denominator of a rational number. Num() function in the Go language returns the numerator of a rational number as the result in integer format. Method-1 Go language program to get the numerator from a rational number. Algorithm Step 1 − Import the fmt and ... Read More

Golang Program to get the denominator from a rational number

Akhil Sharma
Updated on 23-Dec-2022 10:26:31

196 Views

In this article, we will discuss how to get the denominator from a rational number. Rational numbers − In mathematics, rational numbers are defined as numbers that can be expressed in the form of a/b where a and b are integer values. For example- 1/3, 5/8 etc. Note that the denominator of a rational number can never be zero. Syntax func NewRat(a, b int64) *Rat func (x *Rat) Denom() *Int NewRat() function takes two integer numbers as input arguments and returns a rational number in the form of a/b. here a is the numerator and b is the denominator ... Read More

Golang Program to Create an Interface

Akhil Sharma
Updated on 22-Dec-2022 18:24:13

1K+ Views

In this article, we are going to learn about how to create an interface using golang programming INTERFACE − In the go language, an interface is a custom type that is used to specify one or more method signatures. An interface is abstract i.e. we cannot create an instance of the interface but we can create a variable to the interface type and assign this variable to the struct or class that has methods needed by the interface. Syntax type interface_name interface { // method signatures } Example 1 To define an interface first we need ... Read More

Golang Program to Create Abstract Class

Akhil Sharma
Updated on 22-Dec-2022 18:21:48

2K+ Views

In this article, we are going to learn about how to create an Abstract class using Golang Programming Abstract Class − A restricted class is called an abstract class which cannot be used to create an object from it to access an abstract class, it must be inherited from another class. The Go interface lacks fields and forbids the definition of methods inside of it. Any type must implement every interface method in order to belong to that interface type. There are situations in which having a method's default implementation and default fields in GO is helpful. Let's first grasp ... Read More

Golang Program to Create a Class and Object

Akhil Sharma
Updated on 22-Dec-2022 18:20:37

8K+ Views

In this article we are going to learn how to create class and object. Structs − Go language does not have classes. To create an object in the go programming language we can specify structs and store key-value pairs in it. A struct is a user-defined data type that is used to store data together. The values so stored may have the same or different data type. Syntax The syntax to define a structure is as follows − type name_of_struct struct { name_1 type_1 name_2 type_2 name_3 type_3 ... Read More

Golang Program to Convert Linked list to an Array

Akhil Sharma
Updated on 22-Dec-2022 18:19:36

496 Views

In this article we are going to learn about how to convert linked list to an array using golang program. Linked List − Elements in linked lists are typically not stored in close proximity to one another and their storage structures are less rigid, they must be stored with additional tags that refer to the subsequent element. A linked list is a structure that is created dynamically it has two elements in it one is to store the value and the other is to store the address of the next structure. Array − In arrays elements are stored in contiguous ... Read More

Golang Program to Convert Character to String

Akhil Sharma
Updated on 22-Dec-2022 18:30:24

3K+ Views

In this article, we are going to learn about how to convert characters to string go programming language. Chars − Go language does not have a char data type on the contrary characters in go language are represented by rune data type. Rune represents a character value that is encoded in UTF-8 format. The size of the runes is 32-bits. Strings − String data type is used to store a sequence of characters. it can be in the form of literals or alphabets. The size of the string variable is 1 byte or 8 bits. There are two approaches to ... Read More

How to Sort Elements in Lexicographical Order (Dictionary Order) in Golang?

Aman Sharma
Updated on 29-Nov-2022 07:52:53

1K+ Views

In this tutorial, we will write the Golang program to sort the elements in lexicographical order. The tutorial will include three different ways to do this thing. To do the sorting we need to compare two strings and for that, we will use the < operator it will return a boolean value. If the value on the left side is greater than the right side value lexicographically then it will return false else true. For example, Tutorial < Point - The operator will return true. C++ < Golang - The operator will return false. Algorithm Step 1 − Create and ... Read More

How To Perform nCr (r-combinations) in Golang?

Aman Sharma
Updated on 29-Nov-2022 07:50:29

388 Views

In this tutorial, we will perform nCr(r-combinations) in the Golang programming language. The use case of nCr(r-combinations) is to find the total number of possible arrangements where the order does not matter. In other words, we are selecting the r items from n items where the order does not matter. This tutorial will include two ways to find this in the Golang programming language. Explanation For example, for n =5 and r = 3 nCr = n! / ( r! * ( n - r )! ) = 5! / ( 3! * 2! ) = 120 / ... Read More

How to find the Surface area and Volume of Cuboid in Golang?

Aman Sharma
Updated on 29-Nov-2022 07:48:39

113 Views

In this tutorial, we will see the Golang program to find the Surface Area and Volume of a Cuboid. The area is the total space covered by any closed figure. The volume is the capacity to hold something inside the vessel. Formula l - length of a Cuboid h - the height of a Cuboid w - width of a Cuboid. Surface Area of Cuboid - 2*l*w + 2*w*h + 2*l*h For example, the length of a Cuboid is 10 cm, the height is 5 cm and, the width is 8 cm so the Surface Area of a ... Read More

Advertisements