Found 34494 Articles for Programming

Numbers whose Factorials end with n Zeros

Vanshika Sood
Updated on 08-Sep-2023 11:46:46

131 Views

A factorial of a number is the product of all positive integers up to the given number. For example, the factorial of 5 is denoted as 5! and is equal to the product of all positive integers up to 5: 5! = 5 x 4 x 3 x 2 x 1 = 120 The number of zeros at the end of the decimal representation of a number's factorial is referred to as the "trailing zeros" in a factorial. The factorial of 5, for instance, is 120, which has one trailing zero, while the factorial of 10, on the other hand, ... Read More

Leibniz Harmonic Triangle

Vanshika Sood
Updated on 08-Sep-2023 11:19:04

101 Views

The Leibniz harmonic triangle, also known as Leibniz's series or the Leibniz formula, is a triangular arrangement of numbers discovered by German mathematician and philosopher Gottfried Wilhelm Leibniz in the late 17th century. The Leibniz harmonic triangle is a triangular arrangement of fractions. We start at the top with the number and the outermost terms are reciprocal of the natural numbers depicting that particular row number. In general, a term in the leibniz harmonic triangle can be determined by the following equation, where r is the row number and c is the column number with the condition that c

First Occurrence of a Digit in a Given Fraction

Vanshika Sood
Updated on 08-Sep-2023 11:11:02

71 Views

The decimal expansion of a fraction is the decimal representation of the fraction's value. In the following article we discuss two approaches to find the first occurrence of c in a/b. Problem Statement Given three integers a, b, c, locate the first instance of c in the fraction a/b after the decimal point. Print-1 if it does not exist. Sample Examples Input a = 5, b = 6, c = 3 Output 2 Explanation $$\mathrm{\frac{a}{b}=\frac{5}{6}=0.83333}$$ So c=3 occurs at the 2nd place after the decimal point. Hence the output is 2. Input a = -10, b = ... Read More

Minimize the Absolute Difference of Sum of Two Subsets

Vanshika Sood
Updated on 08-Sep-2023 11:06:08

230 Views

To Minimize the Absolute Difference of Sum of Two Subsets, we partition a vector into two subsets i.e. we divide the elements of the vector into two smaller vectors such that each element of the original vector belongs to one of the two smaller vectors, and the two smaller vectors are disjoint. For example, if we have a vector v = {1, 2, 3, 4, 5}, then one possible partitioning of v into two subsets is S1 = {1, 3, 4} and S2 = {2, 5}, where each element of v belongs to either S1 or S2, and the ... Read More

Golang Program to Iterate Map Elements using the Range

Akhil Sharma
Updated on 07-Sep-2023 17:15:48

339 Views

Maps in Golang provide a convenient way to store and access the given data in format of key−value pairs. Iterating over a map allows us to process each key−value pair and perform operations on them. In this article, we will explore different methods to iterate map elements using the range, that includes using the range keyword, using keys and values slices, and using the reflect package. Syntax for key, value := range mapName { // Perform operations on key-value pair } This syntax uses the range keyword to iterate over the elements of ... Read More

Golang Program to Create a Copy of the Map

Akhil Sharma
Updated on 07-Sep-2023 17:12:53

351 Views

Maps are reference data types in Golang, which means that assigning one map variable to another creates a reference to the same underlying data structure. To create an independent copy of a map, we need to use different methods. In this article, we will explore two methods that include the manual method and the copy() function method to create a copy of map in golanguage. Syntax newMap := make(map[keyType]valueType) In this syntax, we first declare a new map named newMap using the make() function, specifying the appropriate key and value types. originalMap := map[string]int The syntax originalMap ... Read More

Golang Program to Delete items of Map

Akhil Sharma
Updated on 07-Sep-2023 17:11:09

2K+ Views

Maps in Go provide a convenient way to store and access data in form of key−value pairs. Deleting items from a map is a common operation when working with dynamic data. In this article, we will delete items of map in golanguage using three methods: the delete() function and iterating over the map, to remove items from a map, and creating a new map based on different conditions. Explanation Maps are versatile structures for holding key−value pairs, and managing these pairs is crucial when dealing with dynamic data. We'll use three approaches to removing items from a map, enhancing ... Read More

Golang Program to Create a Simple Map

Akhil Sharma
Updated on 07-Sep-2023 17:08:37

108 Views

Maps in Go are powerful data structures that allow us to store and retrieve key−value pairs. They are useful for various applications, such as storing and manipulating data, implementing dictionaries, and performing efficient lookups. In this article, we will write a program to create a simple map in golanguage using two methods that include the literal method and the make() function method. Algorithm Declare a map variable using the desired key and value types. Initialise the map using the literal notation by enclosing key−value pairs in curly braces {}. Assign values to the respective keys using the colon ':' ... Read More

Golang Program to Perform Slices Permutations of Numbers Entered by the User

Akhil Sharma
Updated on 07-Sep-2023 17:05:12

206 Views

A slice is a portion of data extracted from an array, list or a data structure. Permutations refer to the rearrangement of elements in a specific order.Here slice permutation means to generate all the possible permutations of the number entered by user. In this article, we will explore how to perform slices permutations of numbers entered by user in Golang, using two methods the recursive approach and the iterative approach, to generate all possible permutations of the given slice. Explanation Recursive: Our first trick is the generatePermutationsRecursive() function. It starts simple, handling small batches of numbers like a warm−up. ... Read More

Golang Program to Print all Permutations of a given String

Akhil Sharma
Updated on 07-Sep-2023 16:54:50

593 Views

A permutation is an arrangement of the characters of a string in a specific order. In some cases we need to print all the permutations of a string to create anagram games or puzzle games where users need to find out the letters hidden in the string. In this article we are going to print all permutations of a string in golanguage using two different approaches that include the recursive and the iterative approach. These methods allow us to generate all possible permutations of a given string, enabling various applications such as generating anagrams, solving permutation−based problems, and more. Explanation ... Read More

Advertisements