c++ program to check whether string is palindrome or not, using library function

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

int main(){
    char string1[20];
    int i, length;
    int flag = 0;
 
    cout << “Enter a string: “;
    cin >> string1;
 
    length = strlen(string1);//using library function
 
    for(i=0;i < length ;i++){
        if(string1[i] != string1[length-i-1]){
            flag = 1;
            break;
  }
}
 
    if (flag==1){
        cout << string1 << ” is not a palindrome” << endl;
    }  
    else {
        cout << string1 << ” is a palindrome” << endl;
    }
 
    return 0;
}

OUT:
Enter a string: wow
wow is a palindrome

Leave a Comment

Your email address will not be published. Required fields are marked *

To Resolve this issue at just 5$ from ServerExpert

https://serverexpert.io/

For Hosting please visit Hostingwebsite.io

You have Successfully Subscribed!

Open chat