Bloomberg LP Interview Question for Financial Software Developers






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

int num_digits(int n) {
int count = 0;
do {
count++;
n /= 10;
} while(n);
}

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

Convert the number to a string and then call the string's length function to give the number of digits

- badalrocks December 20, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

dont forget the "return count;" =P

- Anonymous January 02, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int count =1;
while(n){
n = n/10;
count++
}

- Kiran C January 04, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

This is correct only when n=0. For other numbers it will give one extra count.

- Anonymous March 02, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

What about this:
void num_digits(int n) {
char line[35];
sprintf(line,"%d",n);
return strlen(line);
}

- Leon January 06, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

what if I input a number starts with 0, e.g.00001

- Anonymous March 14, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

what if the number is a float number?
it is safe to convert it into a string, and use string length function. In addition, we need to detect if there is a float point.

- joke January 09, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

log(n)/log(2)

- Anonymous February 20, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

log(n), log shud be taken in base 10

- rama February 20, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

For the log, it should be int( log(n) / log(10)) + 1

- Min September 24, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

log doesnt work for negative numbers ..change for that..also check for case number = 0..

- :P March 06, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

int countDigit(int n){
if(n==0)
return 1;

int abs_n=n>0?n:-n;
int re=0;
while(abs_n>0){
asb_n/=10;
re++;
}

return re;
}

- Anonymous January 06, 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