## Amazon Interview Question for Quality Assurance Engineers

• 0

Team: Kindle
Country: India
Interview Type: Written Test

Comment hidden because of low score. Click to expand.
4
of 4 vote

I think we need to write the test data, not a code.
It should be something like that:
int (2, 2)
number of digits after the coma > precision (2.23434, 1)
number of digits after the coma = precision (3.23, 2)
number of digits after the coma < precision (4.23, 5)
zero (0, 0)
precision zero (3.45, 0)
negative (-1.2334, 3)
negative precision (3.34, -5)
empty ( ,3)
empty precision (3.245, )
etc.

Comment hidden because of low score. Click to expand.
0

Exactly! the question is all about test data generation and not the prog

Comment hidden because of low score. Click to expand.
1
of 1 vote

for the example given, when rounding off to two digits the output should be 3.46, shouldn't it?? or did i miss something?

Comment hidden because of low score. Click to expand.
0

Yes u are right thats a small mistake from my side.....it should round off to 3.46....(i.e to the 2nd decimal place)

Comment hidden because of low score. Click to expand.
1
of 1 vote

Yo can see code + Test cases here www "dot" gohired "dot" in/2014/07/test-cases-for-round-function "dot" html

Comment hidden because of low score. Click to expand.
0

I can confirm that the implementation given at the url is WRONG.

Comment hidden because of low score. Click to expand.
1
of 1 vote

float round(float num, int pre)

``````int mul = pow(10, pre+1);
num = (int)((num * mul + 5)/10);
num /= mul*10;
return num;``````

Comment hidden because of low score. Click to expand.
0
of 0 vote

firstly v can get 3.4567 as .4567 by subtracting the integer part from the no.. then we can multiply by 1000 and then take %10 and then check that number if it is greater than or equal to 5 then v can round off to next digit otherwise keep it as it is

Comment hidden because of low score. Click to expand.
0

there is no point in subtracting to get fractional part you can just ignore the subtraction and continue with the next part

Comment hidden because of low score. Click to expand.
0
of 2 vote

#include<stdio.h>
#include<math.h>
#include<conio.h>
void main()
{
float fl,j;
int n,k,i;
clrscr();
printf("enter float value: ");
scanf("%f",&fl);
printf("enter precision: ");
scanf("%d",&n);
fl=(float)fl*pow(10,n);
printf("%f ",fl);
if((int)(fl*10)%10>=5)
fl=(int)fl+1;
else
fl=(int)fl;
fl=(float)fl/pow(10,n);
printf("%f",fl);
}

Comment hidden because of low score. Click to expand.
0

You Solution seems to be correct.

Comment hidden because of low score. Click to expand.
0
of 0 vote

assert(round(1234.5678, 1) == 1234.6);
assert(round(1234.5678, 2) == 1234.57);
assert(round(1234.5678, 3) == 1234.568);
assert(round(1234.5678, 4) == 1234.5678);
assert(round(0.1234, 1) == 0.1);
assert(round(0.1234, 2) == 0.12);
assert(round(0.1234, 3) == 0.123);
assert(round(0.1234, 4) == 0.1234);

``````double round(double num , int n)
{
unsigned long long tmp, tmp1;
tmp = num * pow(10, n+1);
tmp1 = num * pow(10, n);
if (tmp%10 >= 5)
tmp1++;
return tmp1 / pow(10, n);
}``````

Comment hidden because of low score. Click to expand.
0
of 0 vote

``````#python 3.3.2
import random
def generate_ran_nums():
#
# Generated random data in the format (float(rounded to 4 decimals), randint)
#
num = round(random.uniform(0,9),4)
ran = random.randint(0,9)
return num, ran``````

Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

### Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

### Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.