DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C++ (http://www.daniweb.com/forums/forum8.html)
-   -   Can anyone figure out what is wrong in my program? (http://www.daniweb.com/forums/thread14144.html)

Extreme Nov 16th, 2004 2:21 pm
Can anyone figure out what is wrong in my program?
 
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:-

 
#include<iostream.h>
#include<conio.h>

void main()

{
       
        int n, x, m=0;

        cout<<"Enter any number"<<endl;
        cin>>n;

        while(n>0)

        {

                m*=10;

                x=n%10;

                m+=x;

                n/=10;

        }

        if(m==n)

        cout<<"The entered number is a palindrome number"<<endl;

        else

        cout<<"The entered is not a palindrome number"<<endl;

        getch();

}

Narue Nov 16th, 2004 3:01 pm
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.

Extreme Nov 16th, 2004 3:16 pm
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....

alc6379 Nov 16th, 2004 3:19 pm
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! :D

jwenting Nov 16th, 2004 3:29 pm
Re: Can anyone figure out what is wrong in my program?
 
tx alx, i culdnt ha sd it b8ter mself

muraliaa Sep 16th, 2008 4:43 am
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.

Narue Sep 16th, 2008 9:46 am
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.

niek_e Sep 16th, 2008 10:00 am
Re: Can anyone figure out what is wrong in my program?
 
1 Attachment(s)
This thread is so old, it saw the creation of the previous LHC :)

Ancient Dragon Sep 16th, 2008 12:29 pm
Re: Can anyone figure out what is wrong in my program?
 
Quote:

Originally Posted by Narue (Post 692395)
Congratulations, muraliaa! It took you only four years to come up with the same answer as me.

Some people are just a little slow :)


All times are GMT -4. The time now is 10:21 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC