Hi Guys Im looking for someone who can translate this c++ code to pseudocode .

#include <algorithm>
#include <cctype>
#include <functional>
#include <string>

bool palindrome( unsigned long n )
  unsigned long x = n;
  unsigned long u = 0;
  while (x)
    u *= 10;
    u += x % 10;
    x /= 10;
  return (n == u);

bool palindrome( std::string s )
      std::not1( std::ptr_fun <int, int> ( std::isalnum ) )
  std::transform( s.begin(), s.end(), s.begin(), std::ptr_fun <int, int> ( std::tolower ) );
  std::string z = s;
  std::reverse( z.begin(), z.end() );
  return (s == z);

#include <iostream>
#include <limits>
using namespace std;

int main()
  string        s;
  unsigned long n;
  cout << "Palindrome tester\n";
  cout << "Enter nothing to quit.\n";
  while (true)
    cout << "Enter a string> ";
    getline( cin, s );
    if (s.empty()) break;

    cout << "Enter a number> ";
    cin >> n;
    if (!cin) cin.clear();
    cin.ignore( numeric_limits <streamsize> ::max(), '\n' );

    cout << "The string is " << (palindrome( s ) ? "" : "not ") << "a palindrome.\n";
    cout << "The number is " << (palindrome( n ) ? "" : "not ") << "a palindrome.\n\n";
  cout << "Good bye.\n";
  return 0;



:-O Seriously?

Pseudocode is simply a semi-natural-language summary of the actions performed, or a simplified description of an algorithm. If you understand the C++, you should easily be able to write a summary of the program's actions.

Just read through each line of the code and state what it does...


while (i<10) {
  cout << i << " ";
cout << endl;

the algorithm:

while the value of "i" is less than 10,
  display the value of "i" followed by a "space"
  increment "i"
once loop is complete, output a newline

the pseudocode:

while "i" less than 10,
  output "i"
  output a "space"
  increment "i"
output a newline

Edited 5 Years Ago by Fbody: n/a

hw did u write the code without knwin the pseudocode, jus samar the code

hw did u write the code without knwin the pseudocode, jus samar the code

I won't down vote because you're new, but please don't use SMS/TXT in your posts. This is a professional forum and the rules require that you use proper English to the best of your ability...

Keep it Clear

  • Do post in full-sentence English
  • Do wrap your programming code blocks within [code] ... [/code] tags
  • Do use clear and relevant titles for new threads
  • Do not write in all uppercase or use "leet", "txt" or "chatroom" speak

Let me make an educated guess here.

Your teacher wanted you to make the palindrome problem and you're required to hand in the pseudocode in addition to your solution. Now you've found this code somewhere on the web and decided to cheat your way through this class.

Am I right?

How do I know this you ask? Because your code is written by someone who knows his/her C++ very well; a skill that you clearly lack.


There we go, it was stolen from our own Duoas. One of the usual suspects when it comes to advanced STL use.

Edited 5 Years Ago by Nick Evan: n/a

This article has been dead for over six months. Start a new discussion instead.