Akhil Sharma

Akhil Sharma

507 Articles Published

Articles by Akhil Sharma

Page 27 of 51

Haskell Program to calculate the base 10 logarithm of the given value

Akhil Sharma
Akhil Sharma
Updated on 01-Mar-2023 650 Views

This tutorial will help us in calculating the base 10 logarithm of the given value. A logarithm is a mathematical function that calculates the power to which a number (called the base) must be raised to produce a given value. The base 10 logarithm, is a logarithm in which the base is 10. Method 1: Using Internal Functions In this method, we are going to use build-in log and log base function to calculate bas 10 log of a given number. Algorithm Step 1 − The Prelude library is imported to use log functions. Step 2 − ...

Read More

Haskell Program to calculate the base 2 logarithm of the given value

Akhil Sharma
Akhil Sharma
Updated on 01-Mar-2023 1K+ Views

In Haskell, the logarithm is a mathematical function that calculates the power to which a number (called the base) must be raised to produce a given value. The base 2 logarithm, also known as binary logarithm, is a logarithm in which the base is 2. For example, the base 2 logarithm of 8 is 3, because 2 to the power of 3 equals 8 (2^3 = 8). Method 1: Using logBase function In this method, the log function takes a value of type Double and returns the base 2 logarithm of that value, which is also of type Double. The ...

Read More

Haskell Program to calculate the cube root of the given number

Akhil Sharma
Akhil Sharma
Updated on 01-Mar-2023 735 Views

This Haskell article will help us in calculating the cube root of the given number. The cube root of a number is a value that, when multiplied by itself three times, equals the original number. For example, the cube root of 8 is 2 because 2 x 2 x 2 = 8. In mathematics, cube root of a number x is represented as ∛x. Algorithm Step 1 − Define a user-defined function and name it as cubeRoot Step 2 − Program execution will be started from main function. The main() function has whole control of the ...

Read More

Haskell Program to calculate the square root of the given number

Akhil Sharma
Akhil Sharma
Updated on 01-Mar-2023 4K+ Views

There are different techniques in Haskell to calculate a square root of a number. The square root of a number is a value that, when multiplied by itself, equals the original number. For example, the square root of 9 is 3 because 3 x 3 = 9. Algorithm Step 1 − Defined the square root function Step 2 − Program execution will be started from main function. The main() function has whole control of the program. It is written as main = do. It takes an integer whose square root is to be calculated. Step 3 − ...

Read More

Haskell Program to calculate the area of the rhombus

Akhil Sharma
Akhil Sharma
Updated on 01-Mar-2023 207 Views

In Haskell there are different methods to calculating the area of the rhombus. We can use sides, diagonals and height on the basis of which, its area can be computed by various methods. Algorithm Step 1 − The Text.Printf module is imported. Step 2 − Defined the Rhombus fuction Step 3 − Program execution will be started from main function. The main() function has whole control of the program. It is written as main = do. It takes two integers as diagonals and prints the area using the rhombusArea function. Step 4 − The ...

Read More

Haskell Program to calculate the Lowest Common Multiple

Akhil Sharma
Akhil Sharma
Updated on 01-Mar-2023 748 Views

This tutorial will help us in calculating the Lowest Common Multiple in Haskell Programming. The least common multiple (LCM) is the smallest positive integer that is a multiple of two or more integers. It can be found by listing out the multiples of each number and finding the smallest multiple that is common to all of them. For example, the LCM of 4 and 6 is 12 because 12 is the smallest number that is a multiple of both 4 and 6. Method 1: Using user-defined lcm’ function In this method, the gcd function is used from the Data.List library ...

Read More

Haskell Program to calculate the Highest Common Factor

Akhil Sharma
Akhil Sharma
Updated on 01-Mar-2023 370 Views

This tutorial will help us in calculating the highest common factor using Haskell Programming. The highest common factor (HCF), also known as the greatest common divisor (GCD), is the largest positive integer that divides two or more integers without leaving a remainder. It is a measure of the largest positive integer that can divide two or more integers without leaving a remainder. Method 1: Using user-defined hcf function In this method, the function hcf’ is defined that takes two integers as input, and uses recursion and the modulo operator to repeatedly calculate the remainder of the larger number divided by ...

Read More

Golang program to implement binary tree data structure

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

In the Go, a binary tree is a tree data structure where each node has at most two children, as the left child and the right child. Go's built-in data structures and operations, like structs and pointers, can be used to create a binary tree. The tree's nodes can be visualized as structs with fields for the value kept at each node and pointers to any left or right children. There are three types of tree traversals- preorder, inorder and postorder. We will use two methods to implement the binary tree data structure. In the first method we executed pre-order ...

Read More

Golang program to read and print all files from zip file

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

Golang has packages like os, io, and Archie/zip that can be used to read and print all the files from a zipped file. A zip file is a compressed collection of a set of files/folders. The OS package is used for performing copy operations, the io pacakge is for reading and writing operations whereas the archive/zip package is for unzipping and zipping the file. In this article, we are going to learn about using all these packages to perform the copy and unzipping of the files and printing the same. Method 1: Using io and os package This program uses ...

Read More

Golang program to get all files present in a directory

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

Golang has OS package such as OS.open(), os.closs(), os.copy() and move more that are used for performing different operations with the external files. Similiary we have io package in golang that is used for performing read and write operations on the external file. Here in this article, we are going to use these two packages to print all the files in the given directory. Method 1: Using OS Package This program opens the provided directory and reads its contents using the os package. A slice of os.FileInfo objects, which are returned by the Readdir function and include details about each ...

Read More
Showing 261–270 of 507 articles
« Prev 1 25 26 27 28 29 51 Next »
Advertisements