0
I have a problem
Hello I need to find out how many palindrome numbers are in the range [a, b]. Where did I go wrong? #include<iostream> using namespace std; int main() {int a,b,i,i1,ogl=0,P; cin>>a>>b; for(i=a;i<=b;i++) {i1=i; while(i1!=0) {ogl=ogl*10+i1/10; i1=i1/10; } if(ogl==i) P++; } cout<<P; return 0; }
2 odpowiedzi
+ 2
You need to initialize 'P' to a proper value before performing calculations on it, in this case you will want to give it an initial value of zero. You also need to reset the value of "ogl" inside the loop, otherwise it is going to accumulate the values of all the previous iterations.
0
thanks a lot!