Interview Question for Software Developers


Country: India
Interview Type: In-Person




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

//To count the integer part:
	double f= 53.345;
	int count1 = 0;
	int temp1 = f;
	while (temp1 > 0)
         {
           temp1 = temp /10;
           count1++;
	}
//To count the decimal part
	int count2 = 0;
	int temp2 = f;
	while (double(temp2) != f) {
	f = f * 10;
	temp2 = f;
	count2++;
}

- Chidigam December 29, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

int _tmain(int argc, _TCHAR* argv[])
{
	double f = 53.456;
	int temp1 = f;
	int count1 = 0;
	int count2 = 0;
	while (temp1 > 0)
	{
		temp1 = temp1 / 10;
		count1++;

	}
	int temp2 = f;
	while ((double)temp2 != f) {
		f = f * 10;
		temp2 = f;
		count2++;
	}

	printf("Integer Count = %d, Decimal count = %d", count1, count2);
	return 0;
}

- Chidigam December 29, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

int _tmain(int argc, _TCHAR* argv[])
{
	double f = 53.456;
	int temp1 = f;
	int count1 = 0;
	int count2 = 0;
	while (temp1 > 0)
	{
		temp1 = temp1 / 10;
		count1++;

	}
	int temp2 = f;
	while ((double)temp2 != f) {
		f = f * 10;
		temp2 = f;
		count2++;
	}

	printf("Integer Count = %d, Decimal count = %d", count1, count2);
	return 0;
}

- Anonymous December 29, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int _tmain(int argc, _TCHAR* argv[])
{
	double f = 53.456;
	int temp1 = f;
	int count1 = 0;
	int count2 = 0;
	while (temp1 > 0)
	{
		temp1 = temp1 / 10;
		count1++;

	}
	int temp2 = f;
	while ((double)temp2 != f) {
		f = f * 10;
		temp2 = f;
		count2++;
	}

	printf("Integer Count = %d, Decimal count = %d", count1, count2);
	return 0;
}

- chidigam December 29, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int _tmain(int argc, _TCHAR* argv[])

{

double f = 53.456;

int temp1 = f;
int count1 = 0;
int count2 = 0;
while (temp1 > 0)
{
temp1 = temp1 / 10;
count1++;

}
int temp2 = f;
while ((double)temp2 != f) {
f = f * 10;
temp2 = f;
count2++;
}

printf("Integer Count = %d, Decimal count = %d", count1, count2);
return 0;
}

- Anonymous December 29, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int _tmain(int argc, _TCHAR* argv[])
{
	double f = 53.456;
	int temp1 = f;
	int count1 = 0;
	int count2 = 0;
	while (temp1 > 0)
	{
		temp1 = temp1 / 10;
		count1++;

	}
	int temp2 = f;
	while ((double)temp2 != f) {
		f = f * 10;
		temp2 = f;
		count2++;
	}

	printf("Integer Count = %d, Decimal count = %d", count1, count2);
	return 0;
}

- bhanu.kiran December 29, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

c# implementation.
double data type does not work due to loss of precision while rounding values. Use decimal instead.

static private int[] Get( decimal num ) {

    int[] res = { 1/*before*/, 0/*after*/ };

    var tmpNum = num / 10;
    while (    tmpNum > 1    ) { res[ 0 ]++; tmpNum /= 10; }

    tmpNum = num * 10;
    while ( tmpNum % 10 != 0 ) { res[ 1 ]++; tmpNum *= 10; }

    return res;
}

- zr.roman December 29, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public void countDecimals(double number){
double dupNumber=number;
int i=0;
while(dupNumber>1){
if(dupNumber>1)
i++;
dupNumber=dupNumber/10;
}
System.out.println("Decimals before:"+i);

long temp=(long)number;
BigDecimal difference=BigDecimal.valueOf(number).subtract(BigDecimal.valueOf(temp));
System.out.println("Decimals after:"+difference.precision());
}

- Anonymous December 30, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public void countDecimals(double number){
double dupNumber=number;
int i=0;
while(dupNumber>1){
if(dupNumber>1)
i++;
dupNumber=dupNumber/10;
}
System.out.println("Decimals before:"+i);

long temp=(long)number;
BigDecimal difference=BigDecimal.valueOf(number).subtract(BigDecimal.valueOf(temp));
System.out.println("Decimals after:"+difference.precision());
}

- Zohan December 30, 2015 | Flag Reply


Add a Comment
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.

Learn More

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.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More