Powered by Blogger.

Check Given String is Palindrome or not in C++



Check Given String is Palindrome or not in C++

This code is very simple and easy to write and run. To write this program first get input from use and revers this number, in next step compare output with original number, if both are same it means input number by user is palindrome otherwise not palindrome number. Check Given String is Palindrome or not in C++

#include <iostream>
using namespace std;
int main(){
    char string1[20];
    int i, length;
    int flag = 0;
 
    cout << "Enter a string: "; cin >> string1;
 
    length = strlen(string1);
 
    for(i=0;i < length ;i++){
        if(string1[i] != string1[length-i-1]){
            flag = 1;
            break;
  }
}
 
    if (flag) {
        cout << string1 << " is not a palindrome" << endl;
    }  
    else {
        cout << string1 << " is a palindrome" << endl;
    }
    system("pause");
    return 0;
}

Output

Enter a String: hitesh
hitesh is not a palindrome
Enter a String: sis
sis is a palindrome





facebook
google-plus
twitter
pinterest

No comments :

Post a Comment

HTML Tutorial

images

About Sitesbay

This blog is related to Java Tutorial, C++ Tutorial, C Tutorial, Online Earning tips and more in very simple and easy way. Here i will try to give complete idea related to all new technology.

Java Tutorial

Java is Object oriented programming language, It is more secure and high performance language.

C++ Tutorial

C++ is also Object oriented programming language, It is more simple and easy to learn.

 
https://sitesbay.blogspot.com/?utm_medium=d2898efa59afcc0bc411921036e22b767ca37b09