## Haskell Program to Print Downward Triangle Star Pattern

Updated on 28-Mar-2023 12:45:23

60 Views

## Haskell Program to Calculate the Logarithm Gamma of the Given Number

Updated on 28-Mar-2023 12:20:36

53 Views

## Haskell Program to Find Sum of N Numbers Using Recursion

Updated on 27-Mar-2023 11:44:50

246 Views

In Haskell, we can find Sum of N Numbers by using recursion, tail-recursion and fold-recursion. In the first example we are going to use base case, (sum_n [] = 0) and recursive case, (sum_n (x:xs) = x + sum_n xs)) and in second example, we are going to use, tail-recursion. And in the third example, we are going to use (sumOfN''' xs = foldr (+) 0 xs) function. Algorithm Step 1 − The recursive sum_n function is defined as, For example 1 − sum_n [] = 0 sum_n (x:xs) = x + sum_n xs. ... Read More

## Haskell Program to Find the Product of Two Numbers Using Recursion

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

140 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)) function. And in the second example, we are going to use recursive repeated addition. Algorithm Step 1 − The recursive product’ function is defined as, For example 1 and 2 − product' x y | y == 0 = 0 ... Read More

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

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

193 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) + sumOfDigits (n div 10)) function. And in the second example, we are going to use helper function. Algorithm Step 1 − The recursive sumOfDigits function is defined as, For example 1 − sumOfDigits n | n < 10 = n ... Read More

Previous 1 ... 3 4 5 6 7 ... 19 Next