Recursive problem...

This is a discussion on Recursive problem... within the C++ Programming forums, part of the General Programming Boards category; A palindrome is a word that is spelled exactly the same backwards as forwards(e.g level)write a recursive function that returns ...

  1. #1
    Unregistered
    Guest

    Recursive problem...

    A palindrome is a word that is spelled exactly the same backwards as forwards(e.g level)write a recursive function that returns true if the word given to it is a palindrome

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

    void is_palindrome(string s);

    int main()
    {
    string str;

    cout<<"Please enter a string : "<<endl;
    cin>>str;

    is_palindrome(str);
    return 0;
    }

    void is_palindrome(string s)
    {
    if (s.length()>0)
    {
    is_palindrome(s.substr(1,s.length()-1));
    cout<<s[0];
    }
    }

    i just can use the recursive to cout a backwards of string
    but i don't know how to save it to a variable and compare it..
    Pls help.... Thx...

  2. #2
    Registered User
    Join Date
    Dec 2001
    Posts
    38
    What is the code for substr()? I might be able to help if I can see this.
    SilasP

  3. #3
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    2 comments:

    1. There is much more efficient code you can write without recursion. Only do so if your teacher told you to.

    2. Search the board if you don't have to. There are a billion posts on this.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Recursive Problem.
    By penance in forum C Programming
    Replies: 4
    Last Post: 07-07-2005, 10:16 AM
  2. half ADT (nested struct) problem...
    By CyC|OpS in forum C Programming
    Replies: 1
    Last Post: 10-26-2002, 08:37 AM
  3. recursive function problem
    By jk81 in forum C Programming
    Replies: 2
    Last Post: 10-25-2002, 06:02 AM
  4. binary tree problem - help needed
    By sanju in forum C Programming
    Replies: 4
    Last Post: 10-16-2002, 05:18 AM
  5. Problem with a recursive function
    By fofone in forum C Programming
    Replies: 2
    Last Post: 03-07-2002, 07:21 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21