Found 185 Articles for Haskell

Haskell Program to calculate the cube root of the given number

Akhil Sharma
Updated on 01-Mar-2023 10:06:30

287 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
Updated on 01-Mar-2023 10:05:43

2K+ 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
Updated on 01-Mar-2023 10:03:56

99 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
Updated on 01-Mar-2023 10:01:52

387 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
Updated on 01-Mar-2023 10:00:24

168 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

Haskell Program to read an integer number from the user

Akhil Sharma
Updated on 23-Jan-2023 11:49:39

2K+ Views

This tutorial will help us to read an integer number from the user. The user is prompted to enter any integer number. Then the entered integer is displayed to the console. Method 1: Using read and getLine function This approach uses the read and getLine function to attempt to parse the input as an integer and display the integer number to the console. Algorithm Step 1 − main :: IO () is defining the main function. Step 2 − putStrLn "Enter an integer: " prints the message asking for the user input. Step 3 − input

Haskell Program to find the 1's complement of the given number

Akhil Sharma
Updated on 23-Jan-2023 11:37:24

225 Views

This tutorial will help us to find the 1's complement of the given number. The 1's complement of a binary number is found by inverting each bit of the number. A 1 becomes a 0, and a 0 becomes a 1. This is also known as the bitwise NOT operation. The 1's complement of a number can be useful in certain types of error-detecting and error-correcting Example:s, as well as in certain types of digital logic circuits. The most common use of 1's complement is in signed number representation where it's used to represent negative numbers. For example, if the ... Read More

Haskell Program to find the power of a number using library function

Akhil Sharma
Updated on 01-Mar-2023 10:02:52

162 Views

This tutorial will help us to find the power of a number using library function. The base value and the exponent value is passed as an argument that is used to find the exponent power of the base value passed. And the final output is displayed. For example, For base = 2 ; exponent = 3, it would return 8. Syntax power x y = product (replicate (fromInteger y) x) Product function computes a product of all elements in the list power x y = foldl (*) 1 (replicate (fromInteger y) x) Foldl takes the first item with ... Read More

Haskell Program to read the height of a person and the print person is taller, dwarf, or average height person

Akhil Sharma
Updated on 23-Jan-2023 11:31:38

88 Views

This tutorial will help us in reading the height of a person and printing if the person is taller, dwarf or average height person on being compared. The height value (in centimeters) is passed as argument to the function defined and then the height is being compared with the condition defined in Haskell. And the final output is displayed. Algorithm Step 1 − Program execution will be started from main function. The main() function has whole control of the program. Step 2 − Create user defined function to perform the task Step 3 − The if-else statement is defined ... Read More

Haskell Program to extract the last two digits from the given year

Akhil Sharma
Updated on 23-Jan-2023 11:16:52

317 Views

This tutorial will help us in extracting the last two digits from the given year. The year value is passed as an argument to the function defined and then the last two digits are extracted by using various methods in Haskell. And the final output is displayed. For example, For entered year = 2023, the last two digits = 23. Algorithm Step 1 − The Data.Char module is imported to use digitToInt function. Step 2 − The extractLastTwoDigits function is defined Step 3 − Program execution will be started from main function. The main() function has whole control of ... Read More

Advertisements