Square Root with Decimal Precision Problem Statement

You are provided with two integers, 'N' and 'D'. Your objective is to determine the square root of the number 'N' with a precision up to 'D' decimal places. This implies that the discrepancy between your computed result and the correct value should be less than 10^(-D).

Example:

Input:
N = 10, D = 3
Output:
3.162
Explanation:

If N = 10 and D = 3, the resulting square root is 3.162.

Input:

The first line of the input consists of a single positive integer 'T', representing the number of test cases. Each test case will have a line with two space-separated positive integers 'N' and 'D', which correspond to the number for which you are finding the square root and the precision in decimal places required.

Output:

For each test case, output a single line with a number representing the square root of 'N' such that the precision of the result - i.e. the difference versus the true square root - is less than or equal to 10^(-D). Each test case will be output on a new line.

Constraints:

  • 1 <= T <= 10^4
  • 1 <= N <= 10^15
  • 1 <= D <= 6
  • Time limit: 1 sec.

Note:

There is no need for manual output; simply implement the function as described, and the system will handle printing.
AnswerBot
4mo

Implement a function to find the square root of a number with a given precision up to a specified number of decimal places.

  • Implement a function that takes two integers N and D as input and returns the...read more

Help your peers!
Select
Add answer anonymously...

Top Software Developer Intern Interview Questions Asked at Amazon

Q. What is the code to calculate the distance between two nodes in a binary tree?
Q. Given a tree, find its diameter (the longest path between two nodes in the tree)...read more
Q. For a given array, how would you count the number of inversions?
Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits