-4

I would like someone to help me correct my mistake in this program .

#include<iostream.h>
#include<conio.h>
void main();
{int r,n,Rev=0,temp;

    cin>>n;
    temp=n;
    while(n>0)
        Rev=Rev*10+n%10;
    n=n/10;
    if(temp==Rev)
        cout<<"test is positive";
    else
        cout<<"test is negative";
    getch();
}

Rev means the number we get when reversing the digits.In the case of a positive test, it becomes a palindrome otherwise it does not.Temp is the temporary variable

molbdnilo
  • 64,751
  • 3
  • 43
  • 82
Abhi
  • 1
  • 4
  • 1
    What's happen ? It crashes or just don't work ? – Landelin Delcoucq Sep 02 '16 at 08:42
  • I had given the value n but when I press enter nothing happens.It doesn't even exit or return to my program – Abhi Sep 02 '16 at 08:44
  • how many statement does your while loop contains? should not n = n /10; be a part of while loop? – Shrikant Sep 02 '16 at 08:44
  • I fixed your indentation. You should be able to spot the problem now. Get yourself a real code editor that indents the code for you. – molbdnilo Sep 02 '16 at 08:45
  • Does it compile? I see so many errors – piyushj Sep 02 '16 at 08:46
  • Fyi, you might be surprised at how many hits you get on this site by simply putting `[cpp] palindrome number` in the search box. – WhozCraig Sep 02 '16 at 08:46
  • Thanks.Shrikant,yes n/10 is a part of the while loop – Abhi Sep 02 '16 at 08:46
  • I have compiled it.It doesn't show any errors – Abhi Sep 02 '16 at 08:47
  • WhozCraig:Yeah. and so many down votes too:) – Abhi Sep 02 '16 at 08:48
  • 1
    @Abhi regarding warnings, that's probably because you're using a compiler toolchain that is beyond ancient. Ex: There hasn't been a `iostream.h` since 1998, and *never* supported as part of the standard. It's 2016 ffs. I wish I could find every copy of Turbo C++ on planet earth and wipe it from existence. – WhozCraig Sep 02 '16 at 08:50
  • I am using turbo 3.0 1990 on Windows 7 laptop – Abhi Sep 02 '16 at 08:54
  • Can anyone tell me how to do this program? – Abhi Sep 02 '16 at 08:55
  • 1-(x^2/2!)+(x^4/4!)............. N terms – Abhi Sep 02 '16 at 08:56
  • You have access to Windows 7 as you have stated. You evidently have access to the Internet too. Why don't you just download the latest version of MinGW or Visual C++ or whatever? –  Sep 02 '16 at 09:02
  • Hey Nicky.I am studying only this version in my school.So why should I download Visual C++ which is more complex than this?Also some things in C++ don't work in the Visual C++ – Abhi Sep 02 '16 at 09:05
  • 1
    @Abhi Because you're not learning C++. C++ was standardized in 1998, the latest widely adopted standard, C++11, has been in-industry for over four years now. What you're using, what they're claiming to be *teaching you with*, would not be used in practice. If they were using this antique fossil for an algorithms course of some such, that's one thing. But if this is a C++ course, then you're being flat-out lied to, and it is a disservice to your future profession and ultimately a roadblock in your career. [More reasons **here**](http://stackoverflow.com/a/1962710/1322972). – WhozCraig Sep 02 '16 at 09:17
  • I know it doesn't have much importance in this advanced technological era.But it forms the base for learning other languages.Without C++,we cannot get anywhere.But it's very hard much harder than C.Even the C++ developer Bjarne Stroustroup said,"C makes it easy to shoot in the foot but C++ makes it harder but when you do it it blows your whole leg off" :) – Abhi Sep 02 '16 at 09:27
  • 1
    @Abhi And Turbo C++ is like a gun with a twisted barrel. – πάντα ῥεῖ Sep 02 '16 at 09:54
  • @Abhi I have never said you should. But curiously, why is the complexity (whatever it means) of a compiler being part of your consideration? –  Sep 02 '16 at 09:58
  • @Abhi Yes, something in C++ does not work in Visual C++, but so do Turbo C++ if not more so. What makes you think Turbo C++ coincide with *the definition of C++* more? Just curious. –  Sep 02 '16 at 10:02
  • Possible duplicate of [Checking if a number is a palindrome](http://stackoverflow.com/questions/18849565/checking-if-a-number-is-a-palindrome) –  Sep 02 '16 at 12:49

2 Answers2

1

This line it's outside the while :

  n/n10;

So n is never < 0.

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

        void main();
        {
int r,n,Rev=0,temp;

            cin>>n;
            temp=n;
            while(n>0){
                Rev=Rev*10+n%10;
            n=n/10;
            }

            if(temp==Rev)
                cout<<"test is positive";
            else
                cout<<"test is negative";
            getch();
        }
0
#include<iostream>
    using namespace std;
        int main()
        {
            int num,rev,pal;
            cout<<"Enter number ";cin>>num;
            pal=num;
            for( ;num!=0; )
            {
                rev=(0*10)+num%10;
                num/=10;
            }
            if(pal==rev)
                cout<<"number id palindrome";
            else
                cout<<"Number is not palindrome";
UZAIR69
  • 7
  • 1