Generating all 6-digit palindrome numbers in C++ I just finished my first homework for university where I had to create code that would generate all 6 digit palindrome numbers.

Can someone who has more knowledge give me some tips where I can improve my code?

#include &lt;iostream&gt;
#include &lt;algorithm&gt;
#include &lt;sstream&gt;

using namespace std;

int main(int argc, char* argv[] )
{
  string palindroms;

  for (int iter = 100000; iter &lt;= 1000000; ++iter ) {
    stringstream ss;
    ss &lt;&lt; iter;
    palindroms = ss.str();

    string RevStr = palindroms;
    reverse( RevStr.begin(), RevStr.end() );

    if ( RevStr == palindroms ) {
      cout &lt;&lt; palindroms &lt;&lt; endl;
    }
  }
return 0;
}
I have checked your "brute force" algorithm and though it solves the problem (I have not run it to check), it will have to deal with a lot of work. Why not narrowing the problem a bit? What do we know about palindroms? They read the same from left to right than from right to left.

So if we use that and the fact that our palindroms are six digits long, we would only have to generate all the combinations for the first three digits, then make sure the next three are the same reversed. So:

for( int iter=100; iter&lt;=999; iter++ ) {
  stringstream ss;
  ss &lt;&lt; iter;
  string pal1 = ss.str();
  string pal2 = pal1;
  reverse(pal2.begin(), pal2.end());

  cout &lt;&lt; pal1 &lt;&lt; pal2 &lt;&lt; endl;
}