Found 33676 Articles for Programming

Golang Program to Print The Height of a Binary Tree

Akhil Sharma
Updated on 20-Jul-2023 15:20:01

386 Views

A binary tree is a tree which has at most two children and height refers to the no. of levels in the tree. In this article, we will use two examples to find the height of a binary tree. In this Golang article we will write programs to print the height of a binary tree. 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 values followed by the values to add. ... Read More

Golang Program to Merge Two Sorted Linked Lists

Akhil Sharma
Updated on 20-Jul-2023 15:16:38

988 Views

In this article, we will write Go language programs to merge two sorted linked lists. A linked list is a set of two fields with the value that is the data and the next pointer which points to the next node in the list. A linked list is a dynamic data structure with two pointers head and tail, where head points to the first value and tail points to the last value. Here, we will use two examples to merge the sorted linked list. Demonstration This demonstration represents two sorted linked lists “LIST1” and “LIST2”. we need to merge these ... Read More

Golang Program To Print Descending Order Pattern

Akhil Sharma
Updated on 20-Jul-2023 15:14:44

159 Views

In this Go language article, we will write programs to print descending order patterns using a nested for loop as well as using the two nested loops inside the outer loop. Descending order pattern means the higher order elements are placed first and in pattern the rows with highest no. of rows is placed first. Demonstration This demonstrates a descending order pattern where every row starts from 1 and decreases by 1 at each column until the end of row. In the top row it has 1-6 numbers and in second row it has 1-5 and it goes on till ... Read More

Golang Program to Print Right Pascals Triangle

Akhil Sharma
Updated on 20-Jul-2023 15:13:57

126 Views

A pascals triangle is a form of triangle in which binomial coefficients are arranged in triangular form. Here, the triangle starts with 1 and in every row the beginning and ending digit is 1. In this article, we will write Golang programs to print right pascals triangle. Demonstration This demonstration explains a right pascal triangle, in which every row shows the coefficient of binomial expansion for the power of (a+b)^n, where a and b =1. The first row has single 1, second row has 1 and 1 , the third row has 1, 2 and 1 and so on. 1 ... Read More

Golang Program to Build Right Triangle Using Numbers

Akhil Sharma
Updated on 20-Jul-2023 15:13:05

106 Views

In this article, we will write Golang programs to build a right triangle using numbers. The numbers imply that the triangle is composed of numbers. There are many ways to perform this operations, here we have used different examples to provide a better understanding of the concept. Demonstration This demonstration explains a right angled triangle representation using numbers. Each row of this triangle is consist of number starting from 1 to the row number. From top the first row has 1, second row has 1, 2 and it goes on. 1 1 2 1 2 3 1 ... Read More

Golang Program to Count no. of Numerical Digits in a String

Akhil Sharma
Updated on 20-Jul-2023 15:02:06

1K+ Views

A Golang string is a sequence of characters created using quotes. Strings are immutable here, which means once created cannot be modified. Here we will work on strings to find numerical digits present in them.In this article, we will write a Go language program to count no. of numerical digits in a string. Demonstration This demonstration explains that “helloalexa234567playthesong” is an input string and it contains six numeric digits, the role of the program is to tally all the numeric digits available in the provided string. Input string − helloalexa234567playthesong Number of Numeric Digit − 6 Syntax unicode.IsDigit() ... Read More

Golang Program to Implement Slices

Akhil Sharma
Updated on 20-Jul-2023 14:58:04

239 Views

A slice in golang is a dynamic array created to add extra elements which cannot be added in an array as it has a fixed size. In this particular article, two examples are used to demonstrate the use of slices. In both of the examples, various operations are performed on the slices to show its working. In the first example, a slice of string is created and in the second example, slice of integers is created. Let’s see the operations via examples to get a crystal-clear understanding of the concept. Syntax funccopy(dst, str[] type) int The copy function in ... Read More

Golang Program to Create Slice of Slices

Akhil Sharma
Updated on 20-Jul-2023 14:55:51

404 Views

A slice in go language is a variable length array which means that values can be added and deleted from it as per convenience. In this article, we will create a slice of slices using two examples, slice of slices means that many slices are contained in a slice. In the first example, we will demonstrate the creation of slice of slices in two ways, firstly we will initiate the slice of slices with some values and in the second way an empty slice of slices will be created in which values will be appended later on. In the second ... Read More

Golang Program to Create Slice Using Composite Literal

Akhil Sharma
Updated on 20-Jul-2023 14:53:46

190 Views

In Go programming language, a composite literal is used to create a slice, array, struct etc object of type given and initializes it. In this article, we will create a slice using three examples. In the first example, slices of numbers will be created, in the second example, slices of strings will be created and in the third example, built-in functions are used to create slices. In this way the creation of slices is demonstrated. Let’s see the examples to get a crystal-clear view of the concept. Syntax func make ([] type, size, capacity) The make function in go ... Read More

Golang Program to Show Use of this Keyword in Class

Akhil Sharma
Updated on 20-Jul-2023 14:52:10

369 Views

In Go programming language, there is no concept of classes so struct are used to demonstrate the use of this keyword in class. The "this" keyword refers to the current method or object that is currently being executed in the program. In this article we will use two examples to see how the program works. In the first example, we will use Child struct by calling the method on this struct and printing its name and age whereas in the second example, we will use a Rectangle struct to print its area by calling the method on this struct. Let’s ... Read More

Advertisements