
Asked in Amazon
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!
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?
Interview Questions Asked to Software Developer Intern at Other Companies
Top Skill-Based Questions for Amazon Software Developer Intern
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Operating Systems Interview Questions and Answers
250 Questions
System Design Interview Questions and Answers
250 Questions
C++ Interview Questions and Answers
150 Questions
Stay ahead in your career. Get AmbitionBox app


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
AmbitionBox Awards
Get AmbitionBox app

