Palindrome Program in C++ (For String)
This is the solution of palindrome program in C++ / Cpp
What is palindrome :
Ans: Palindrome is a type of number or string which will be same when we operate a negative 1 loop on it
For Ex; NAYAN is Same as Its mirror image NAYAN so it is A Palindrome String,
SHIVAM is Not same as its mirror image of negative loop image which is MAVIHS , SO It is Not A Palindrome , Here 121 is a palindrome but 211 is not and 1553443551 is a palindrome number.
CODE: PALINDROME OF STRING IN C++
#include <iostream>
#include <cstring>
using namespace std;
int main(){
string i;
bool k;
cout<<"Enter the string : ";
cin>>i;
for(int o=0;o<i.length();o++)
i[o]=toupper(i[o]);
int n=i.length();
for(int l=0;l<n;l++){
if(i[l]==i[n-1-l]){
k=1;
}
else {
cout<<"Not a palindrome"<<n;
return 0;
}
};
if (k){
cout<<"PALINDROME";
return 1;
}
cout<<"NOT PALINDROME";
return 0;
}
Comments
Post a Comment