Found 31499 Articles for Programming

Golang to remove null from a slice

Akhil Sharma
Updated on 23-Jan-2023 14:48:17
In this article, we will learn how to remove a null value from a slice using a variety of examples. A slice is a sequence of elements just like an array. An array is a fixed sequence of elements whereas a slice is a dynamic array, meaning its value is not fixed and can be changed. Slices are more efficient and faster than arrays moreover; they are passed by reference instead of value. Let us learn through examples how it can be executed. Method 1: Using For Loop In this method, we will see how to remove a null value ... Read More

Golang program to calculate the sum of right diagonal elements

Akhil Sharma
Updated on 23-Jan-2023 14:44:46
In this article, we will learn how to calculate the sum of right diagonal matrix with the help of different examples. A matrix is a 2-d array. The output will be printed on the screen using fmt.println() function which is a print statement in Golang. 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 − create a function main, in that function create a matrix, and fill with some values inside it. Step 3 − Print the ... Read More

Golang program to calculate the sum of left diagonal matrix

Akhil Sharma
Updated on 23-Jan-2023 14:41:36
In this article, we will learn how to calculate the sum of left diagonal matrix with the help of different examples. A matrix is a 2-d array. The left diagonal matrix is printed using the logic of indexes equal to each other. The output will be printed on the screen using fmt.println() function which is a print statement in Golang. 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 − Create a function main and in that ... Read More

Golang program to print the left diagonal matrix

Akhil Sharma
Updated on 23-Jan-2023 14:39:06
In this article, we will see how to print the left diagonal matrix with the help of suitable examples. A matrix is a 2-d array. Here in the examples, we will use a nested for loop which will iterate through the rows and columns of the matrix to print the left diagonal matrix. The output will be printed on the screen using fmt.println() function which is a print statement in Golang. 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 ... Read More

Golang program to print right diagonal matrix

Akhil Sharma
Updated on 23-Jan-2023 14:36:40
In this article, we will see how to print the right diagonal matrix with the help of suitable examples. A matrix is a 2-d array. Here in the examples, we will use a nested for loop which will iterate through the rows and columns of the matrix to print the right diagonal matrix. The output will be printed on the screen using fmt.println() function which is a print statement in Golang. 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 ... Read More

Golang program to initialize a slice

Akhil Sharma
Updated on 23-Jan-2023 14:34:56
In this article, we will learn how to initialize a slice using a variety of ways in examples. A slice is a sequence of elements just like an array. An array is a fixed sequence of elements whereas a slice is a dynamic array, meaning its value is not fixed and can be changed. Slices are more efficient and faster than arrays moreover they are passed by reference instead by value. Let’s learn through examples how it can be executed. Algorithm Step 1 − Create a package main and declare fmt(format package) package in the program where main produces ... Read More

Find the maximum element of each row in a matrix using Python

Vikram Chiluka
Updated on 23-Jan-2023 14:28:16
In this article, we will learn a python program to find the maximum element of each row in a matrix. Assume we have taken an NxN input matrix. We will now find the maximum element of each row in an input matrix using the below methods. Methos Used The following are the various methods to accomplish this task − Using Nested For Loops Using max() function Using map(), lambda functions Method 1: Using Nested For Loops Algorithm (Steps) Following are the Algorithm/steps to be followed to perform the desired task. − Create a function maximumRowElement() to print ... Read More

Find the least frequent element in an array using Python

Vikram Chiluka
Updated on 23-Jan-2023 14:25:33
In this article, we will learn the python program for getting the least frequent element in an array. Methods Used The following are the various methods to accomplish this task − Using sort() function(Naive Approach) Using Hashing Using Counter() Function Method 1: Using sort() function(Naive Approach) Running two loops is a simple fix. The outer loop selects each element one by one. The inner loop calculates the frequency of the selected element and compares it to the least value reached thus far. This solution's time complexity is O(n^2) Sorting is a better solution. The array is sorted first, ... Read More

Decoding and encoding hexadecimal digitals using Python

Vikram Chiluka
Updated on 23-Jan-2023 14:23:43
In this article, we will learn how to decode and encode hexadecimal digits using python. Methods Used Using binascii module Using the base64 module Method 1: Using Binascii Module There are several methods to convert between binary and different ASCII-encoded binary representations in the binascii module. Use the binascii module if all you need to do is encode or decode a raw string of hex digits. Algorithm (Steps) Following are the Algorithms/steps to be followed to perform the desired task. − Use the import keyword to import the binascii module. Create a variable to store the ... Read More

Decimal Equivalents of 1/2, 1/3, . . . ,1/10 in Python

Vikram Chiluka
Updated on 23-Jan-2023 14:12:17
In this article, we will learn a python program that prints out the decimal equivalents of 1/2, 1/3, 1/4, . . . ,1/10. Methods Used The following are the various methods to accomplish this task − Printing Decimal Equivalent of 1/2 Using the range() function Using the decimal module Method 1: Printing Decimal Equivalent of 1/2 We can easily use this code to find the decimal equivalents of 1/2. In this code, we just display the output after storing the result of 1/2 in a variable, inputNumber. Example The following program returns the decimal equivalents of 1/2 − ... Read More
Previous 1 ... 3 4 5 6 7 8 9 ... 3150 Next
Advertisements