The code is working, but unreadable. How to simplify it.
#include <iostream> using namespace std; void main() { int num; cin >> num; int roz = 1; int res = num; while( res / 10 ) { ++roz; res = res / 10; } int left = 0; int right = 0; bool answer = false; for( int i = roz; i >= 1; i-- ) { for( int j = -roz; j < 0; j++ ) { left = int( num / pow( 10, i - 1 ) ) % 10; right = int( num / pow( 10, roz + j ) ) % 10; cout << left << " || " << right << endl; if( left == right ) { i--; answer = true; continue; } else { answer = false; } i = 0; break; } } answer ? ( cout << "yes" ) : ( cout << "no\n" ); }
void main()2) forgotten either<math.h>or<cmath>. PS Do you have to work with the number? Since it is entered, it is entered as a string, and the detection of a palindrome in a string is much easier. - PinkTuxpow()and nested loops, :) - PinkTux