Akhil Sharma has Published 671 Articles

Haskell Program to Find the Product of Two Numbers Using Recursion

Akhil Sharma

Akhil Sharma

Updated on 27-Mar-2023 11:43:58

306 Views

In Haskell, we can find the Product of Two Numbers by using recursion along with recursive repeated addition. In the first example we are going to use (product' x y | y == 0 = 0 | y == 1 = x | otherwise = x + product' x (y-1)) ... Read More

Haskell Program to Find Sum of Digits of a Number using Recursion

Akhil Sharma

Akhil Sharma

Updated on 27-Mar-2023 11:43:33

368 Views

In Haskell, we can find Sum of Digits of a Number by using recursion along with mod, div and other helper functions. getCurrentTime and NominalDiffTime function. In the first example we are going to use (sumOfDigits n | n < 10 = n | otherwise = (n `mod` 10) ... Read More

Haskell Program to Calculate the Execution Time of Methods

Akhil Sharma

Akhil Sharma

Updated on 27-Mar-2023 11:42:53

563 Views

In Haskell, we can use getCurrentTime and NominalDiffTime functions to calculate the Execution Time of Methods. In the first example we are going to use (startTime

Haskell Program to calculate the power using Recursion

Akhil Sharma

Akhil Sharma

Updated on 27-Mar-2023 11:42:11

502 Views

In Haskell, we can calculate the power by using recursion along with cases and also by using tail-recursion. In the first example we are going to use recursion along with base case, (power _ 0 = 1) and recursive case, (power x y = x * power x (y-1)). In ... Read More

Haskell Program to Reverse a Sentence Using Recursion

Akhil Sharma

Akhil Sharma

Updated on 27-Mar-2023 11:39:48

286 Views

In Haskell, we can reverse a Sentence by using recursion along with concatenation and also by using list comprehension. In the first example we are going to use recursion along with base and recursive case and in the second example, we are going to use concatenation as ((last sentence) : ... Read More

Haskell Program to Find G.C.D Using Recursion

Akhil Sharma

Akhil Sharma

Updated on 27-Mar-2023 11:32:34

109 Views

In Haskell, we can find G.C.D by using recursion and also by using recursive case statements. In the first example we are going to use recursion along with base and recursive case and in the second example, we are going to use (case (x, y) of) statement. Algorithm Step ... Read More

Haskell Program to Find Factorial of a Number Using Recursion

Akhil Sharma

Akhil Sharma

Updated on 27-Mar-2023 11:31:56

767 Views

In Haskell, we Find Factorial of a Number Using Recursion by using recursion along with foldl and product function. In the first example we are going to use recursion along with base and recursive case and in the second example, we are going to use factorial n = foldl (*) ... Read More

Haskell Program to Find the Sum of Natural Numbers using Recursion

Akhil Sharma

Akhil Sharma

Updated on 27-Mar-2023 11:30:58

178 Views

In Haskell, we Find the Sum of Natural Numbers by using recursion and tail-recursion. In the first example we are going to use recursion along with base and recursive case and in the second example, we are going to use sumNat function and third example, we are going to use ... Read More

Haskell Program to Check Whether a Number can be Expressed as Sum of Two Prime Numbers

Akhil Sharma

Akhil Sharma

Updated on 27-Mar-2023 11:30:06

114 Views

In Haskell, we will Check Whether a Number can be Expressed as Sum of Two Prime Numbers by using user-defined functions. In the first example we are going to use (isPrime) function along with primeSum function and in the second and third example, we are going to use (isPrime) function ... Read More

Haskell Program to Check if An Array Contains a Given Value

Akhil Sharma

Akhil Sharma

Updated on 27-Mar-2023 11:11:52

387 Views

In Haskell, we will Check if An Array Contains a Given Value by using recursion and foldr & elem functions. In the first example, we are going to use base and recursive cases and in the second example, we are going to use (containsValue x = foldr (\y acc -> ... Read More

Advertisements