Question

5- Implement and test the following function: //bool ispalindrome(string s) //return true iff s is a palindrome //For example: ispalindrome(RADAR) return true, ispalindrome (ABCD) returns false. Enter word to find if the word is palindrome: RADAR The word is RADAR a palindrome Press any key to continue Enter word to find if the word is palindrome: ABCDEF The word is ABCDEF is not a palindrome Press any key to continue
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>
#include <string>
using namespace std;
//is Pallindrom function to check given string is pallindrom or not
bool isPalindrome(string s){
   int   i=0; //i points to starting charecter
   int j=s.length()-1; //j points to last charecter
   while(i<j){
       //if charecter at i and charecter at jth position not equal it is not a pallindrome
       if(s[i]!=s[j]){
           return false; //not pallindrome
       }
       //updating i,j
       i++;
       j--;
   }
   return true;//pallindrom
}
//main function
int main(){
   string str;
   cout<<"Enter word to find if the word is pallindrome:";
   cin>>str;//taking string

   if(isPalindrome(str)){
       cout<<"The word is "<<str<<" is pallindrome"<<endl;
   }
   else{
       cout<<"The word is "<<str<<" is not pallindrome"<<endl;
   }
}

CProgram Flles (x8bDev-CppyconsolePauser.exe nter word to find if the word is pallindrome RADAR The word is RADAR is pallindr
Add a comment
Know the answer?
Add Answer to:
Implement and test the following function://bool ispalindrome(string s)//return true iff s is a palindrome//For example: ispalindrome("RADAR")...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT