Found 1082 Articles for Go Programming

Golang program to get the current weekday

Akhil Sharma
Updated on 03-Apr-2023 13:22:12

256 Views

In this Go language article, we will write proCurrent weekday implies the current day in the week which can be obtained using numerous methods. In this program we will use three examples to get the current weekday for which time package will be imported in the program, it helps in viewing the time. Syntax func Now() Time The Now() function is defined in time package. this function generates the current local time. To use this function, we have to first import the time package in our program. time.Format() This function belongs to the time package. It is used ... Read More

Golang program to get current time zone

Akhil Sharma
Updated on 03-Apr-2023 13:19:11

4K+ Views

Golang has internal functions like Now() Time, and other Time functions that can be used for getting the current time zone. Current time zone in Go is a time zone where people reside in and see the same standard time. In a country like India IST is observed throughout the nation. In this program we will discuss how to obtain current time zone using two examples. Syntax func Now() Time The Now() function is defined in time package. this function generates the current local time. To use this function, we have to first import the time package in ... Read More

Golang program to create a hash collection

Akhil Sharma
Updated on 03-Apr-2023 13:18:29

143 Views

In this article, we will write a Golang programs to create hash collections with the help of make function and map function. Hashmap stores key value pairs that can be accessed via index. In this program we will create a hash collection with the help of two examples. 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. Using Make Function In this method, we will create a hashmap with the help of a make ... Read More

Golang program to demonstrate a simple module

Akhil Sharma
Updated on 03-Apr-2023 13:17:34

101 Views

In this Go language article, we will write programs to demonstrate a simple module. A module in Go is called as the collection of packages namely we can call it packages and sub-packages where the root file will be called as go.mod. In this program we will demonstrate a module using three different examples. 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 Example1: Golang program to demonstrate a simple module using basic printing ... Read More

Golang program to create a module with variables

Akhil Sharma
Updated on 04-Apr-2023 08:24:15

275 Views

In golang we can create a module with variable using const or var keywords, orelse we can even import the module . A module in Go is a group of packages. It helps in managing the distribution of the package. 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 Output. Step 2 − In the first step, create three variables name, age and address using var keyword and assign these variables the desired values. Step 3 − Then, create a ... Read More

Golang program to perform binary search on a slice of custom structs

Akhil Sharma
Updated on 03-Apr-2023 13:14:13

689 Views

In this Golang article, we are going to perform binary search on a slice of custom structs using iterative and recursive method. Binary search is a search algorithm used to find the position of a specific value within a sorted sequence of elements. Algorithm Step 1 − First, we need to import the fmt package. Step 2 − Create a custom Person structure with string type name and integer type age. Step 3 − Now, create a bSearch() function that is used to perform binary search on a slice of Person struct. Step 4 − It initializes the low ... Read More

Golang program to check if a stack is empty

Akhil Sharma
Updated on 03-Apr-2023 13:13:45

157 Views

In this Golang article, we are going to check if a stack is empty using iterative and recursive method. A stack is a linear data structure that follows the Last-In-First-Out (LIFO) principle. Algorithm Step 1 − First, we need to import the fmt and strconv package. Step 2 − Create a stack structure with an item slice to store the stack elements. Step 3 − Now, define the functions, push(), pop() and peek() to perform the basic operations with the stack. Step 4 − push() adds the item to the end of the stack while pop() removes the last ... Read More

Golang program to reverse a stack

Akhil Sharma
Updated on 03-Apr-2023 13:13:14

152 Views

In this Golang article, we are going to reverse a stack using recursive and iterative method. A stack is a linear data structure that follows the Last-In-First-Out (LIFO) principle. Algorithm Step 1 − First, we need to import the fmt and strconv package. Step 2 − Create a stack structure with an item slice to store the stack elements. Step 3 − Now, define the functions, push(), pop(), peek(), isEmpty() and print() to perform the basic operations with the stack. Step 4 − push() adds the item to the end of the stack while pop() removes ... Read More

Golang program to find if there exists a pair of numbers in an array that add up to a given target sum using two pointer approach

Akhil Sharma
Updated on 03-Apr-2023 13:12:40

223 Views

In this Golang article, we are going to find if there exists a pair of numbers in an array that add up to a given target sum using two pointer approach with iterative and optimized-iterative method. An array is a collection of elements of the same data type, arranged in a contiguous block of memory, and accessed using an index or a subscript. Using Two Pointer Approach With Iterative Method In this method, we will define a pairWithGivenSum() function using iterative approach that is used to find if there exists a pair of numbers in an array that add up ... Read More

Golang program to find longest subarray with a given sum using two-pointer approach

Akhil Sharma
Updated on 03-Apr-2023 13:12:02

197 Views

In this Golang article, we are going to find longest subarray with a given sum using two-pointer approach with iterative and optimized-iterative method. An array is a collection of elements of the same data type, arranged in a contiguous block of memory, and accessed using an index or a subscript. Using Two-Pointer Approach With Iterative Method In this method, we will define a longestSubarray() function using iterative approach that is used to find longest subarray with a given sum using two-pointer approach. Algorithm Step 1 − First, we need to import the fmt package. Step 2 − Start the ... Read More

Advertisements