Found 33676 Articles for Programming

Golang Program to delete an item from the array without using the library function

Akhil Sharma
Updated on 16-Feb-2023 18:58:49

588 Views

An array in go language is defined as the data structure that is used to store elements in contiguous memory locations. Arrays allow us to search and store elements at constant time. arrays use index to store elements which starts from 0 and goes to n – 1, where n is the length of the array. Method 1: Using An External User-Defined Function The following method, illustrates how we can remove a particular integer element from the array of integers using an external function. Algorithm Step 1 − Import the fmt package. Step 2 − Defining a function named ... Read More

Golang Program to insert an item into the array without using library function

Akhil Sharma
Updated on 16-Feb-2023 18:54:02

168 Views

An array in go language is defined as the data structure that is used to store elements in contiguous memory locations. Arrays allow us to search and store elements at constant times. arrays use the index to store elements that start from 0 and goes on to n – 1, where n is the length of the array. Algorithm Step 1 − First, we need to import fmt package. Step 2 − Now, start the main() function. Inside the main() initialize an array of strings. Step 3 − In order to add values to this array we have to ... Read More

Golang Program to read and print two-dimensional array

Akhil Sharma
Updated on 16-Feb-2023 18:53:27

3K+ Views

What is a 2D array? A two-dimensional array is a collection of data that are arranged in rows and columns. In go we can use the for loops to iterate and print elements of the 2d arrays. Here is an example of the same below − 0 1 2 4 5 6 8 9 10 Method 1: Using For Loops In this method, we will use for loops in golang to iterate over the arrays and catch each element then we will print that element unless the whole array is iterated upon. Algorithm ... Read More

Golang Program to calculate the sum of columns of matrix elements

Akhil Sharma
Updated on 16-Feb-2023 18:50:22

454 Views

A matrix is a collection of numbers arranged in rows and columns, a two-dimensional array, each of the values of this matrix is known as an element. Here we will use three methods to find the sum of column elements and compare each method for the same using go programming. Here is an example of a matrix and the sum value of it’s columns − The given matrix is − 0 1 2 4 5 6 8 9 7 Sum of elements in column 1 is 12 Sum of elements in column 2 ... Read More

Golang Program to calculate the sum of rows of matrix elements

Akhil Sharma
Updated on 16-Feb-2023 18:46:50

543 Views

A matrix is a collection of numbers arranged in rows and columns, a two-dimensional array. Here we will use three methods to find the sum of elements and compare each method for the same using Go Programming language. Algorithm Step 1 − Import the fmt package. Step 2 − Now we need to start the main() function. Step 3 − Then we are creating a matrix naming matrix. Step 4 − Print the matrix on the screen using fmt.Println() function. Step 5 − Initialize a new variable called sum of type int to hold the resultant sum. Step ... Read More

Golang Program to Determine the class of an object

Akhil Sharma
Updated on 16-Feb-2023 18:46:01

134 Views

What are Objects in Golang? Objects are defined on the structs and store Key-value pairs of data together in go programming. There are numerous methods for producing an object. A struct is a user-defined type that groups together a collection of fields (also known as properties or data members) and methods. A struct can be defined using the type keyword, followed by the struct name and a struct literal that defines the fields of the struct. Method 1: Using a user-defined function Algorithm Step 1 − First, we need to import the fmt package. Step 2 − Then we ... Read More

Go language Program to calculate the sum of matrix elements

Akhil Sharma
Updated on 16-Feb-2023 18:45:05

188 Views

What is a Matrix? A matrix is a collection of numbers that are arranged in rows and columns, which is a two-dimensional array. Here we will use three examples to find the sum of elements and compare each element of the matrix for the same using the Golang program. Algorithm Step 1 − Import the fmt package. Step 2 − Now we need to start the main() function. Step 3 − Then we are creating a matrix naming matrixA. Step 4 − Print the matrix on the screen using fmt.Println() function. Step 5 − Initialize a new variable called ... Read More

Golang Program to Show Usage of Static keyword in Class

Akhil Sharma
Updated on 16-Feb-2023 18:34:38

2K+ Views

What is Static Keyword in Golang? The term "static" is used to describe variables, functions, and methods that have a fixed or unchanging value or behavior. In Go, the static keyword does not exist. In go we use the term "variables" to describe the memory locations where data is stored and manipulated. Static variables have a property of preserving their value even after they are out of their scope! Hence, static variables preserve their previous value in their previous scope and are not initialized again in the new scope. Algorithm Step 1 − First, we need to import ... Read More

Golang Program to Add Two Complex Numbers by Passing Class to a Function

Akhil Sharma
Updated on 16-Feb-2023 18:32:02

203 Views

In this article, we will write a go language program to add two complex numbers by passing a class to a function. Here we will create a function to the class that will accept the class as an argument along with its properties and we can easily calculate the sum of the provided complex numbers using it. Algorithm Step 1 − First, we need to import the fmt package. Step 2 − Then, create the structure named Complex and define in it the properties real and imaginary. Step 3 − Then create a function to the complex class declared ... Read More

Golang Program to Print Boundary Elements of a Matrix

Akhil Sharma
Updated on 16-Feb-2023 18:31:35

202 Views

What is Boundary Elements? In go programming language. the boundary elements of a matrix are the elements that are located on the outer edge of the matrix. They are located at four positions i.e the first row, the last row, the first column and at the last column. In a matrix of size m x n, the top boundary elements are the elements in the range matrix[0][0] to matrix[0][n-1], the bottom boundary elements are the elements in the range matrix[m-1][0] to matrix[m-1][n-1], the left boundary elements are the elements in the range matrix[0][0] to matrix[m-1][0], and the right boundary elements ... Read More

Advertisements