Palindromes

My program is supposed to print all numbers smaller than user-inputted number 'n' which are palindromes. It compiles, but when I input a number into n, it doesn't give me any answer. What do I need to change?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
using namespace std;
int main()
{
    int n, m, d, r=0;
    cout<<"Enter a positive number: "<<endl;
    cin>>n;
    
    while(n>0)
    {
              n=m;
    
    while(n!=0)
    {
              d=n%10;
              r=(r*10)+d;
              n=n/10;
    if(r==m)
    {
            cout<<m<<" is a palindrome."<<endl;
            m--;
    }
    }
    }
cout<<endl;
system("pause");
return 0;
}
Last edited on
what is the value of m?

while(n>0)
{
n=m;
Line 5: m is an uninitialized (garbage) variable.

Line 11: You're overlaying the value input with a garbage value.
Topic archived. No new replies allowed.