30 Day Risk-Free Guarantee:
100% money back if you're unsatisfied.
Book (308 Pages):
  • 150 Programming Interview Questions and Solutions
  • Five Proven Approaches to Solving Tough Algorithm Questions
  • Ten Mistakes Candidates Make -- And How to Avoid Them
  • Steps to Prepare for Behavioral and Technical Questions
  • Interview War Stories: A View from the Interviewer's Side
  • Book Preview and More Info

Video (One Hour):
  • Watch CareerCup's founder perform a totally unscripted technical interview of a candidate.
  • Overview of what interviewers look for in software engineering jobs.
  • Technical questions with white-boarding coding where the candidate does well - and struggles.
  • Interviewer reviews with what went well and poorly.
  • Video Preview and More Info

Resume Review (24 - 48hr)
  • Get your resume reviewed by a trained engineering interviewer. More Info
All Products / Services


Express Prep Package (Book)
$29.99 for e-book | $32.45 for paperback
Buy E-Book Buy on Amazon


Standard Prep Package (E-Book & Video)
Emailed Instantly | $39.99
Buy Standard

Elite Prep Package (E-Book, Video & Resume)
Emailed Instantly | $99.99
Buy Elite
 



Check whether the number is palindrome or not without using array?
Convert the 6 decimal system into 10 decimal system?

17


geniusxsy on November 09, 2009 |Edit | Edit

reverse, compare.
what is 6 decimal system??? base_6 representation?

particularraj on November 09, 2009 |Edit | Edit

how can you reverse a number? You have to change it to a string?

theory on November 09, 2009 |Edit | Edit


// count the number of digits.
count=0;
while(n) {++count;n/=10}

// now compare digits
for(i=1;i<count/2;++i){
if(n/pow(10,count-i) != n % pow(10,i)
return false;
}

anon on November 09, 2009 |Edit | Edit

i=1;i<=count/2;i++

geniusxsy on November 09, 2009 |Edit | Edit

sloppy code.
u really need to practice more coding

geniusxsy on November 09, 2009 |Edit | Edit

void palindrome(int n){
int reverse_n=0, int tempn=n;
while(n){
reverse_n*=10;
reverse_n+=n%10;
n/=10;
}
return tempn==reverse_n;
}

Raj on November 09, 2009 |Edit | Edit

dude you are just reversing it. NOT checking it.

srini on February 12, 2010 |Edit | Edit

geniusxsy's code is right...
but just change the return type...(raj might be confused)

geniusxsy on November 09, 2009 |Edit | Edit

void palindrome(int n){
int reverse_n=0, int tempn=n;
while(n){
reverse_n*=10;
reverse_n+=n%10;
n/=10;
}
return tempn==reverse_n;
}

Gajanan on February 07, 2010 |Edit | Edit

This seems precise answer.

Tejas on November 09, 2009 |Edit | Edit

Here is the logic,

bool palindrome(int n){

int reverseNumber = 0, constantFactor = 10, remainder = 0;
int originalNumber = n;

while(n){
remainder = n%constantFactor;
n /= 10;

reverseNumber = remainder + reverseNumber * constantFactor;
}

return originalNumber == reverseNumber;
}

QQQ on November 12, 2009 |Edit | Edit

private static bool isP(int n)
{
int m = n;
int p = 0;

while (n > 0)
{
p = p * 10 + n % 10;
n /= 10;
}
return (m == p);
}

nPcomplete on November 26, 2009 |Edit | Edit

int palindrome(int n)
{
int rev = 0;
int tmp = n;
int k;
while(tmp!=0)
{
k = tmp%10;
tmp = tmp/10;
rev = rev*10;
rev = (rev+k);
}
printf("rev--%d \n",rev);
while(rev!=0)
{
if(rev%10 !=n%10)
return 0;
rev = rev/10;
n = n/10;
}
return 1;
}

Bhushan on December 13, 2009 |Edit | Edit

Algo:
1: convert the number into staring using itoa, ltoa or whatever suitable in-built function
2: take size of the string, n
3: then compare the i and n-i positions, increment i everytime till you reach the half

please correct me if i am wrong

kunalchopra on December 31, 2009 |Edit | Edit

wrong, no conversion to string allowed. cannot use an array.

Anonymous on May 21, 2010 |Edit | Edit

bool palindrome(int num){
int reversenum, remainder;
int tmp=num;
if(tmp>0){

while(tmp)
{
remainder=tmp%10;
tmp=tmp/10;
reversenum=reversenum*10+remainder;
}
return (!(num^reversenum));
}
}

NKD on July 11, 2010 |Edit | Edit

bool palindrome(int n)
{
int m = 1;
int x = n/10;
while(x)
{
m *=10;
x/=10;
}
bool Ispalindrome = true;
while(n)
{
if((n/m) != (n%10))
{
Ispalindrome = false;
break;
}
n %= m;
n /=10;
m /=100;
}
return Ispalindrome;
}

Add a Text Comment | Add Runnable Code
Name:
Comment:

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








Amazon (1033)Bloomberg LP (403)Qualcomm (117)Adobe (88)Goldman Sachs (78)NetApp (49)IBM (43)Morgan Stanley (33)CapitalIQ (30)Sophos (25)Achieve Internet (23)Electronic Arts (19)Motorola (18)Research In Motion (17)Flipkart (16)
Microsoft (867)Google (141)NVIDIA (98)Yahoo (82)Epic Systems (69)Expedia (47)VMWare Inc (43)Apple (32)Cisco Systems (28)Facebook (23)Infosys (22)Agilent Technologies (19)Sage Software (17)Deshaw Inc (16)FlexTrade (15)
More Companies »
Software Engineer / Dev... (1062)Financial Software Deve... (170)Testing / Quality Assur... (56)Analyst (35)Virus Researcher (25)Field Sales (15)Developer Program Engin... (9)Front-end Software Engi... (6)MyJoB (5)area sales manager (4)Assistant (3)Cabin crew (2)Accountant (1)personnel (1)Intern (1)
Software Engineer in Te... (288)Program Manager (65)Development Support Eng... (47)INTERN(MSIDC) (28)Web Developer (18)System Administrator (10)Consultant (10)Production Engineer (5)Associate Technology L2 (5)AcquireKnowledge (4)Product Security Engine... (3)Solutions Architect (2)Gamer (1)mts (1)Fresh graduate interview (0)
More Job Titles »
Algorithm (1073)Terminology & Trivia (294)C (166)Object Oriented Design (159)Java (121)Testing (114)Arrays (101)Operating System (78)Database (70)Linked List (62)String Manipulation (56)Networking / Web / Inte... (44)Threads (36)Linux Kernel (33)PHP (22)
Coding (511)C++ (204)Behavioral (159)Data Structures (155)Experience (116)Brain Teasers (111)Computer Architecture &... (79)General Questions and C... (73)Trees and Graphs (69)Math & Computation (57)Application / UI Design (45)Ideas (38)System Design (35)Puzzles (30)Bit Manipulation (20)
More Topics »
CareerCup Official Interview Book Daily Questions Requests for Help Mock Interviews Video for Cracking the Coding Interview Job Placement Service CareerCup Blog
My Profile Edit Profile & Email Settings Sign Out