2016-10-28 15 views
-1

再帰回文機能 これは 回文一部ではありませんが、あなたがif文の中の方法ispalindrome(word, strlen(word))を呼び出す必要が再帰回文機能

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

bool ispalindrome(char string1[],int length); 
int main() 
{ 
    string word; 
    cout<<"Enter a word: "; 
    cin>> word; 

    if(ispalindrome) 
    cout<<"The input word is palindrome"; 
    else 
    cout<<"The input word is NOT palindrome"; 

    return 0; 
    } 

    bool ispalindrome(char string1[],int length) 
    { 

if(length<=1) 
    return true; 
if ((*string1)==string1[length-1]) 
return ispalindrome(string1+1, length-2); 

else return false; 

} 

答えて

0

を印刷していない私の溶液中のmistack質問の解決に私があります。

だから、また、この

if (ispalindrome(word, strlen(word)) { 
    cout << word << " is a palindrome" << endl; 
} else { 
    cout << word << " is not a palindrome" << endl; 
} 

のように見えるあなたのタイプと一致して滞在する必要があります。 wordcharアレイであり、stringではありません。

+0

あなたがエラーを書いたものをinteredにしたとき、それはこのリンクにあります。 http://store2.up-00.com/2016-10/1477696622041.png –

+0

@ sh.alzoubiだから私はあなたがあなたのタイプと一致している。 'word'は' char * word = new char [1024] 'として宣言しなければなりません。 –

+0

私は単語をcharに変更しました。これは私が受け取ったエラーです http://store2.up-00.com/2016-10/1477749413741.png –