Question

Haskell Define function-divisors that receives a number and returns a list of all divisors of that...

Haskell

Define function-divisors that receives a number and returns a list of all divisors of that number.For example, if the input is 20, then the output would be[1,2,4,5,10,20]. You may use list comprehension, list ranges, and function mod for this purpose.Hint:Given numbern, consider all numbers from 1 ton, and then keep only the ones that dividen.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE:

divisors :: Integer -> [Integer] --function declaration

divisors x =[ y | y<-[1..x], x `mod` y ==0] --function definition

main = do

print(divisors 20) --calling a function


SCREENSHOT:


SAMPLE OUTPUT:

***Please upvote if it helps and feel free to comment if you have any query

Add a comment
Know the answer?
Add Answer to:
Haskell Define function-divisors that receives a number and returns a list of all divisors of that...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT