Akhil Sharma

Akhil Sharma

507 Articles Published

Articles by Akhil Sharma

Page 39 of 51

Golang Program to find the Distinct elements from two arrays

Akhil Sharma
Akhil Sharma
Updated on 09-Feb-2023 1K+ Views

In this tutorial, we will see to write a go language program to find distinct elements in two arrays. In this article we will write two programs. In the first program we will use the array of strings while in the second one we will use the array of integers. Algorithm STEP 1 − import the fmt package. STEP 2 − Define three functions named intersection(), uniquearr1 and uniquearr2. STEP 3 − The intersection() finds the common array elements from the two arrays while the other two functions remove that common elements from given arrays. STEP 4 − All these ...

Read More

Golang Program to find the index of the first occurrence of the specified item in the array

Akhil Sharma
Akhil Sharma
Updated on 09-Feb-2023 1K+ Views

In this article we will write a go language program to find the index of the first occurrence of the specified item in an array. we will use for loops and inbuilt go library functions to achieve the result. Method 1: Using SearchInts() Library Function Syntax func Sort(data Interface) The sort() function is present in sort package. this function is used to sort an array in ascending order. The array to be sorted is passed as an argument to the function. The time complexity of this function is O(n * logn). type IntSlice []int The IntSlice() function is ...

Read More

Golang Program to insert multiple elements into the array from the specified index

Akhil Sharma
Akhil Sharma
Updated on 09-Feb-2023 1K+ Views

In this tutorial, we will write a go language program to insert multiple elements into an array at the specified index. There are many methods to add elements into an array. it can be done by either using indexing or by using for loops. There are some inbuilt functions too using which we can add elements at specified index. 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 append(slice, element_1, element_2…, element_N) []T ...

Read More

Golang Program to insert an element into the array at the specified index

Akhil Sharma
Akhil Sharma
Updated on 09-Feb-2023 3K+ Views

In this tutorial, we will write a go language program to insert an element into an array at the specified index. There are many methods to add elements to an array. it can be done by either using indexing or by using for loops. There are some inbuilt functions too using which we can add elements at the specified indexes. 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 append(slice, element_1, element_2…, element_N) ...

Read More

Golang Program to find the uncommon elements from two arrays

Akhil Sharma
Akhil Sharma
Updated on 09-Feb-2023 477 Views

In this tutorial, we will see to write a go language program to find uncommon elements in two arrays. In this article we will write two programs. In the first program we will use the array of strings while in the second one we will use the array of integers. Algorithm STEP 1 − import the fmt package. STEP 2 − Define three functions named intersection(), uniquearr1 and uniquearr2. STEP 3 − The intersection() finds the common array elements from the two arrays while the other two functions remove that common elements from given arrays. STEP 4 − All these ...

Read More

Golang Program to reverse the elements of the array using inbuilt function

Akhil Sharma
Akhil Sharma
Updated on 09-Feb-2023 1K+ Views

In this tutorial, we will write a go language program to reverse the elements of the array using inbuilt functions. in this program we will see how we can reverse an array of strings and integers using internal go functions. Method 1: Using Append() and Make() 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 func append(slice, element_1, element_2…, element_N) []T The append function is used to add values to an array ...

Read More

Golang Program to convert Binary to Octal

Akhil Sharma
Akhil Sharma
Updated on 09-Feb-2023 452 Views

In this article you will learn the go language code to convert binary number to octal number. Binary numbers are the numbers that have base 2, i.e., each digit can have only 2 possibilities 0 and 1. Octal numbers are the numbers that have base 8, i.e., each digit can have only 8 possibilities from 0 to 7. Algorithm STEP 1 − Import the fmt package. STEP 2 − Start the main function and initialize the required variables of type int naming binary, octal, remainder and j. store initial values to them. STEP 3 − Store the binary number chosen ...

Read More

Golang Program to get the first given number of items from the array

Akhil Sharma
Akhil Sharma
Updated on 09-Feb-2023 231 Views

In this tutorial, we will write a go language program to get the first given number of items from an array. We can do this by either using the inbuilt functions in go or by using for loops. The first method is more efficient in functionality than the second one but we will discuss both these methods in this program. Method 1: Getting items from an array of integers using internal functions In this method, we will write a go language program to get the first given number of items from an array by using the append() library function. Syntax ...

Read More

Golang program to show overloading of methods in class

Akhil Sharma
Akhil Sharma
Updated on 01-Feb-2023 2K+ Views

In this article, we will learn how to overload the method in class using different example. Go programming language does not have concept of a class so function overloading will be used to execute the program. As a result, code can be more flexible and readable. As an illustration, you could create a function that accepts an interface as a parameter and then call it with several types that implement the interface. Let’s see it execution. Method 1: using custom type MyInt Here, it contains two methods Print() and PrintWithNumber() where values can be sent in these functions of MyInt ...

Read More

Golang program to check if a string is empty or null

Akhil Sharma
Akhil Sharma
Updated on 01-Feb-2023 18K+ Views

String in Golang is a collection of characters. Since strings in Go are immutable, they cannot be modified after they have been produced. Concatenating or adding to an existing string, however, enables the creation of new strings. A built-in type in Go, the string type can be used in a variety of ways much like any other data type. Syntax strings.TrimSpace() To eliminate leading and trailing white space from a string, use the strings.TrimSpace() function. Algorithm Step 1 − Create a package main and declare fmt(format package) package. Step 2 − Create a main function. Step 3 − Using internal ...

Read More
Showing 381–390 of 507 articles
« Prev 1 37 38 39 40 41 51 Next »
Advertisements