Bloomberg L.P.

  www.bloomberg.com
  www.bloomberg.com

Interview Question

Financial Software Developer Interview New York, NY

How do you reverse a number without storing it in an array

  Ex: 412 should be printed as 214
Answer

Interview Answer

3 Answers

0

I gave an answer but they told me that I am using un-necessary multiplications and divisions,

Interview Candidate on Feb 15, 2012
2

int reverse(int n){
    int rev = 0;
    while(n!=0){
        rev = rev*10 + n%10;
        n = n/10;
    }

    return rev;
}

Anonymous on Oct 3, 2012
0

int reverse(int n){
if(n==0) return;
int tmp=n%10;
reverse(n/10);
printf("%d",tmp);}

yifeng on Dec 6, 2012

Add Answers or Comments

To comment on this, Sign In or Sign Up.