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
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
Write a Haskell function integerSqrt that returns the integer square root of a positive integer n....
A positive integer n is “perfect” if the sum of its positive factors, excluding itself, equals n. Write a perfect function in Haskell that takes a single integer argument and returns the list of all perfect numbers up to that argument. Report all of the perfect numbers up to 1000 (i.e. call 1000)
MATLAB Question: TASK 5 12 MARKS -L06N] The rounded-square-root (RSR) of a positive integer n is defined as the square root of n rounded to the nearest integer. Adapting Heron's method to integer arithmetic allows the rounded-square-root of n to be calculated as follows. Let d be the number of digits of number n d-1 If d is odd, then Xo = 2 × 107- If d is even, then Xo-7 × 107- where xo is the starting guess for...
IN PYTHON: Write a function that takes, as an argument, a positive integer n, and returns a LIST consisting of all of the digits of n (as integers) in the same order. Name this function intToList(n). For example, intToList(123) should return the list [1,2,3].
Write a recursive function named arithmeticSum that takes a positive integer parameter n and returns the sum of the integer numbers from 1 to n Please write in C++
Convert the code you developed to obtain square root value into a function that returns square root of a float value argument. The answer is of float type. This function can be named sqrtC and it has one (float) parameter going in and one value (the result) coming out. Write code in C language.
1) a) Write MATLAB function that accepts a positive integer parameter n and returns a vector containing the values of the integral (A) for n= 1,2,3,..., n. The function must use the relation (B) and the value of y(1). Your function must preallocate the array that it returns. Use for loop when writing your code. b) Write MATLAB script that uses your function to calculate the values of the integral (A) using the recurrence relation (B), y(n) for n=1,2,... 19...
I got a C++ problem. Let n be a positive integer and let S(n) denote the number of divisors of n. For example, S(1)- 1, S(4)-3, S(6)-4 A positive integer p is called antiprime if S(n)くS(p) for all positive n 〈P. In other words, an antiprime is a number that has a larger number of divisors than any number smaller than itself. Given a positive integer b, your program should output the largest antiprime that is less than or equal...
Write a Python function isPrime(number) that determines if the integer argument number is prime or not. The function will return a boolean True or False. Next, write a function HowManyPrimes(P), that takes an integer P as argument and returns the number of prime numbers whose value is less than P. And then write a function HighestPrime(K) that takes integer K as an argument and returns the highest prime that is less than or equal to K. USE THE WHILE LOOP...
For integer n € {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15) function hex(n) returns hexadecimal character from F. Write function hex and use it to create the function HEX(N) that for integer N>0 displays its value hexadecimal form. For all programs use C++, and make all programs as short as possible. Write the main program that supports the following sample dialog: Enter a positive integer : 13 Hexadecimal value D Enter a positive integer : 255 Hexadecimal value Enter a positive integer ; 1234567 Hexadecimal value...
Consider the function defined by f(n) = 2 nwhere n is a positive integer. (i) Can this function be computed by a Turing machine? Why or why not? (ii) Is this function primitive recursive? Why or why not?