943,900 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 3135
  • C++ RSS
Nov 16th, 2004
0

Can anyone figure out what is wrong in my program?

Expand Post »
I need to make a program to check if the entered number is palindrome or not i.e. if u take a number and reverse it it will be the same old number for example if u take 121..then if u reverse the number it will be 121 and so 121 is a palindrome number.

i wrote a program to check if a number is palindrome or not but it is not working properly :cry: ...Can any1 plz tell me wat is wrong..

The program which I wrote is below:-

C++ Syntax (Toggle Plain Text)
  1.  
  2. #include<iostream.h>
  3. #include<conio.h>
  4.  
  5. void main()
  6.  
  7. {
  8.  
  9. int n, x, m=0;
  10.  
  11. cout<<"Enter any number"<<endl;
  12. cin>>n;
  13.  
  14. while(n>0)
  15.  
  16. {
  17.  
  18. m*=10;
  19.  
  20. x=n%10;
  21.  
  22. m+=x;
  23.  
  24. n/=10;
  25.  
  26. }
  27.  
  28. if(m==n)
  29.  
  30. cout<<"The entered number is a palindrome number"<<endl;
  31.  
  32. else
  33.  
  34. cout<<"The entered is not a palindrome number"<<endl;
  35.  
  36. getch();
  37.  
  38. }
Last edited by alc6379; Nov 16th, 2004 at 3:20 pm. Reason: added [code] tags
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Extreme is offline Offline
12 posts
since Nov 2004
Nov 16th, 2004
0

Re: Can any1 figure out wat is wrong in my program!!PLZ!!

>if(m==n)
n is zero at this point, remember? Use a copy of n for your loop counter so that the original value is preserved.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Nov 16th, 2004
0

Re: Can any1 figure out wat is wrong in my program!!PLZ!!

Hey thanx a lot Narue...my program is working Perfectly now!! :cheesy:

And once again Thanx a lot....
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Extreme is offline Offline
12 posts
since Nov 2004
Nov 16th, 2004
0

Re: Can any1 figure out wat is wrong in my program!!PLZ!!

Just a helpful hint here on the forum for you:

Cn u plz not use chat spk here? Wat do u want 2 do that for? U got all d time in d world 2 make a post, so there's no need 2 uz chat spk n here.

Please, for all of our eyes' sakes, spend about 30 seconds more on your post, and spell words in a non-lame fashion.

kthxbye!
Team Colleague
Reputation Points: 186
Solved Threads: 147
Cookie... That's it
alc6379 is offline Offline
2,519 posts
since Dec 2003
Nov 16th, 2004
0

Re: Can anyone figure out what is wrong in my program?

tx alx, i culdnt ha sd it b8ter mself
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Sep 16th, 2008
0

Re: Can anyone figure out what is wrong in my program?

Your program is write up to if(m==n)

in the above program n will become zero
after the loop. So assign n value to any other variable,then compare with m.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
muraliaa is offline Offline
2 posts
since Jul 2008
Sep 16th, 2008
1

Re: Can anyone figure out what is wrong in my program?

Congratulations, muraliaa! It took you only four years to come up with the same answer as me.
Last edited by Narue; Sep 16th, 2008 at 9:46 am.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Sep 16th, 2008
1

Re: Can anyone figure out what is wrong in my program?

This thread is so old, it saw the creation of the previous LHC
Attached Thumbnails
Click image for larger version

Name:	largehadroncollidertp3.jpg
Views:	34
Size:	90.2 KB
ID:	7400  
Moderator
Featured Poster
Reputation Points: 4142
Solved Threads: 394
Industrious Poster
Nick Evan is offline Offline
4,132 posts
since Oct 2006
Sep 16th, 2008
0

Re: Can anyone figure out what is wrong in my program?

Click to Expand / Collapse  Quote originally posted by Narue ...
Congratulations, muraliaa! It took you only four years to come up with the same answer as me.
Some people are just a little slow
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,953 posts
since Aug 2005

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Accessing a constructor of a different class
Next Thread in C++ Forum Timeline: Display thumbnail and text in a list in VC++?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC