Bool recursive function about palindrome|Homework

Hello I need some help here
I don't have ideas to code a bool recursive function about palindrome.
How to return the value in bool function instead of 1,0?
Can someone give me some ideas about this function?
Thanks a lot.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Check if a positive integer is a Palindrome
#include <iostream>
using namespace std;

bool isPalindrome( int number, int factor );

int main()
{
   int number; // a positive integer
   cout << "Enter a positive integer: ";
   cin >> number;

   // puts 10^(numDigits-1) (i.e., the smallest numDigits-digit positive integer) into factor
   int temp = number;
   int factor = 1; // power of ten
   while( temp > 9 )
   {
      temp /= 10;
      factor *= 10;
   }

   // print whether the number is a palindrome
   if( isPalindrome( number, factor ) )
      cout << endl << number << " is a palindrome." << endl << endl;
   else
      cout << endl << number << " is not a palindrome." << endl << endl;

   system( "pause" );
}
bool isPalindrome( int number, int factor ){
}
Last edited on
closed account (48T7M4Gy)
http://www.cplusplus.com/forum/beginner/177310/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include<iostream>
#include<string>
using namespace std;
string str;
bool f(int fi,int li){
if(fi<=li){
if(str[fi]==str[li]){
     //cout<<   str[fi]<<" "<<str[li]<<" ";          //help you to understand recurtion
    fi=fi+1;
    li=li-1;
    bool r= (true and f(fi,li));
    //cout<<r<<endl;                                        // same
    return r;

}else{return false;}
}else{return true;}

}

int main(){

getline(cin,str);
int l=str.length();
cout<<l<<str<<endl;
cout<<boolalpha;
cout<<f(0,l-1);


return 0;
}
my program is a case sensitive
Topic archived. No new replies allowed.