Question

Write a Haskell function integerSqrt that returns the integer square root of a positive integer n....

Write a Haskell function integerSqrt that returns the integer square root of a positive integer n. (The integer square root is defined to be the largest integer whose square is less than or equal to n, i.e. the result of integerSqrt 15 is 3.). integerSqrt :: Integer -> Integer

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

ANSWER:

AS PER THE QUESTION GIVEN

Haskell function

A program in Haskell which returns the integer square root of a positive integer n.

--function declaration
integerSqrt :: Int -> Int
--function definition
integerSqrt num = aux num
where
    aux temp
      | temp * temp > num = aux (temp - 1)
      | otherwise = temp


main = do
   -- display message
   putStrLn "Integer square root is: "
   --calling a function
   print(integerSqrt 15)   

The screenshot of the above code is given below:

OUTPUT:

Integer square root is:                                                                                                              

3

IF YOU HAVE ANY DOUBTS COMMENT BELOW I WILL BE THERE TO HELP YOU

​​​​​​​THANKS

Add a comment
Know the answer?
Add Answer to:
Write a Haskell function integerSqrt that returns the integer square root of a positive integer n....
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