Server Side Programming Articles

Page 1674 of 2109

Golang program to find the prime numbers from the array

Akhil Sharma
Akhil Sharma
Updated on 13-Feb-2023 575 Views

In this tutorial, we will showcase how to find the prime numbers from the array using different examples. Prime numbers are those numbers which are either divisible by 1 or by themselves they have no factor other than this. Now we will present you few illustrations to help you get clear with the logic behind this program. Method 1: Finding Prime Number in the main Function In this particular method, we will print the prime numbers with the help of nested for loops. We will half the array elements in every inner iteration and check whether they are divisible or ...

Read More

Golang program to fetch elements from an array based on an index

Akhil Sharma
Akhil Sharma
Updated on 13-Feb-2023 961 Views

In this tutorial, we will learn how to fetch elements from an array with the help of index using different examples to showcase what methods can be applied to it and the result obtained will be printed on the console using the print function in Golang. Method 1: Using an Array Index In this method, we will see how to fetch element from an array using index in for loop and this is one of the simplest methods to solve this problem, lets have a look at this example to understand it. Algorithm Step 1 − Create a package main ...

Read More

Golang Program to remove given element from the array

Akhil Sharma
Akhil Sharma
Updated on 13-Feb-2023 4K+ Views

In this tutorial, we will learn how to remove an element from an array using simple for loop approach. The logic behind this approach is that create a new array and the particular index element which is to be removed don’t add it to the new array. Let’s have a look how to execute it with the use of different examples. Remove Element from the Array in main Function In this method, we will execute the entire program inside main function. An original array and a new array will be created to execute the removal of elements from the array. ...

Read More

Golang program to illustrate the creation of strings

Akhil Sharma
Akhil Sharma
Updated on 13-Feb-2023 228 Views

In this tutorial, we will see how strings are created in Golang. There are different ways to create strings which we will learn via some examples. In Golang a string is a sequence of variable-width characters where each character is represented by one or more bytes. Method 1: Using double Quotes with Shorthand Declaration In this method, we will learn about how to create strings using shorthand declaration. Let’s dive into the code to understand it. Algorithm Step 1 − Create a package main and import fmt package in the program. Step 2 − Create a function main and further ...

Read More

Golang Program to search an item into the array using interpolation search

Akhil Sharma
Akhil Sharma
Updated on 13-Feb-2023 337 Views

In this tutorial, we will see how to search an item in the array using interpolation search. It is very similar to Binary search but is an improved version of it, in this algorithm the element is searched from the sorted array using a different method to find middle element and the output is printed using print function in Golang. Let’s have a look to understand it − Using interpolation search in main method In this method, we will learn how to search an element in the array using an interpolation search method. All the things will be executed in ...

Read More

Golang Program to print a hollow star triangle pattern

Akhil Sharma
Akhil Sharma
Updated on 10-Feb-2023 358 Views

In this tutorial, we will learn how to print hollow star triangle pattern using Go programming language. The user can specify the maximum number of rows to print as an inverted pyramid star pattern using this GO programmed. Here, we'll print the inverted Pyramid of * symbols up till the user-specified rows are reached. Algorithm STEP 1 − Import the package fmt STEP 2 − Start function main() STEP 3 − Declare and initialize the variables and assign value to them. STEP 4 − Initialize a variable to store the number of rows that star pattern should print. STEP 5 ...

Read More

Golang Program to Create an enum class

Akhil Sharma
Akhil Sharma
Updated on 10-Feb-2023 565 Views

An enum combines related constants into a single type. Enums are a strong feature with many applications. However, compared to the majority of other programming languages, they are implemented very differently in Go. In this article, we'll see how to use a predeclared identifiable iota to implement enums in Golang. IOTA − Iota is an identifier that is used with constants and can make auto-increment number-based constant definitions simpler. The keyword "iota" stands for an integer constant that begins at zero. Implementing Iota package main import "fmt" const ( c0 = iota + 1 ...

Read More

Golang Program to get the flattened 1D array

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

In this tutorial, we will write a go language program to get the flattened 1D array from a multidimensional 2D array. A multi-dimensional array is an array of arrays, where each inner array represents a row of elements. A 1D array, on the other hand, is a single array that contains all the elements of the multi-dimensional array in a contiguous manner. 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 ...

Read More

Golang Program To Find the Trace and Normal of a given Matrix

Akhil Sharma
Akhil Sharma
Updated on 10-Feb-2023 281 Views

In this tutorial we will write an article to find the normal and trace of a matrix. A matrix is considered to be normal if its square root equals the sum of the squares of each member and trace is the total of a matrix's diagonal elements. Finding Normal of the given Matrix Algorithm STEP 1 − First we need to import the fmt and math package. STEP 2 − Create a function to find the Normal of the matrix. This function uses two for loops to find the square of each element. STEP 3 − Update the sum variable ...

Read More

Golang Program to get the subarray from an array using a specified range of indices

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

In this tutorial, we will write a go language program to get the sub array from an array using a specified range of indices. A subarray is a contiguous portion of an array, specified by a range of indices. For example, given the array [1, 2, 3, 4, 5] and the range of indices [1, 3], the resulting subarray would be [2, 3, 4]. 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 ...

Read More
Showing 16731–16740 of 21,090 articles
Advertisements