logo CodeStepByStep logo

sqrt

Language/Type: C++ loops

Write a function named sqrt that accepts an integer N as a parameter and returns the square root of N as an integer. The challenge here is that you must not use sqrt or pow or other library functions to calculate the square root; rather, you must compute it yourself. You should return the square root as a truncated integer; for example, the square root of 7 is approximately 2.65, but your function should return 2. You may assume that the value of N passed is a positive integer.

Function: Write a C++ function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.