PayPal Interview Question
99 Interview Reviews |
Back to all PayPal Interview Questions & Reviews
Interview questions and reviews posted anonymously by interview candidates
Interview Question for Software Engineer at PayPal:
Consider the following function: int f (int num) { int out = 0; for (; num > 0; num /= 10) { int d = num % 10; out *= 10; out += d; } return out; } 1) What does it do? 2) Write the same algorithm using recursion
| Tags: | programming See more , See less 8 |
Helpful Question?
Yes |
No
Inappropriate?
Answers & Comments (3)
int f(int num)
{
if((num/10) == 0)
return num;
else
return ( 10(num%10) + f(num/10) );
}
Helpful Answer?
Yes |
No
Inappropriate?
inf f(int num, int car=0)
{
car *=10;
if((num/10) == 0)
return ( car + num );
else
return f(num/10, car+(num%10) );
}
Helpful Answer?
Yes |
No
Inappropriate?
To comment on this
question,
Sign In with Facebook or
Sign Up
0 of 0 people found this helpful
by Paul:
the output parameter b will be the reverse result.
void rev(int d, int& b)
{
b *= 10;
if (d/10 == 0)
b += d;
else
{
b += d%10;
rev(d/10, b);
}
}