C++ Program to Check String is Palindrome or Not
Write C++ Program to Check String is Palindrome or Not
// CPP Program to Check String is Palindrome or Not #include <iostream> #include <string.h> using namespace std; int main() { char S1[100] = "NAINA", S2[100]; strcpy(S2, S1); int i = 0, temp; int n = strlen(S1); while(i < n/2) { temp = S1[i]; S1[i] = S1[n-i-1]; S1[n-i-1] = temp; i++; } cout << "String :--> " << S2; if(strcmp(S2,S1)!=0) { cout << "\nString is not Palindrome"; } else { cout <<"\nString is palindrome"; } return 0; }
Output:
Run 1:
String :--> NAYAN
String is palindrome
Run 2:
String :--> NAINA
String is not Palindrome