xxxxxxxxxx
#include<iostream>
#include<ctype.h>
using namespace std;
int main() {
string s; cin >> s;
int a = 0;
for(int i = 0; i < (s.length() / 2); i++)
if(s[i] == s[s.length() - 1 - i]) a++;
if(a == (s.length() / 2)) cout << "YES";
else cout << "NO";
return 0;
}
xxxxxxxxxx
// Check whether the string is a palindrome or not.
#include <bits/stdc++.h>
using namespace std;
int main(){
string s;
cin >> s;
int l = 0;
int h = s.length()-1;
while(h > l){
if(s[l++] != s[h--]){
cout << "Not a palindrome" << endl;
return 0;
}
}
cout << "Is a palindrome" << endl;
return 0;
}
xxxxxxxxxx
#include<iostream>
using namespace std;
int main()
{
string s1, s2;
cout << "Enter string: ";
cin >> s1;
for (int i = s1.length()-1; i >= 0; i--)
{
s2 += s1[i];
}
if (s1 == s2)
{
cout << "Palindrome!" << endl;
}
else
{
cout << "Not Palindrome!" << endl;
}
return 0;
}
xxxxxxxxxx
class Solution{
public:
int isPalindrome(string S)
{
// Your code goes here
int n=S.length();
for(int i=0;i<n/2;i++)
{
if(S[i]!=S[n-1-i])
{
return 0;
}
}
return 1;
}
};
xxxxxxxxxx
#include <iostream>
bool isPalindrome (int number) {
int decomposed = number, reversed = 0;
while (decomposed) {
reversed = 10 * reversed + (decomposed % 10);
decomposed /= 10;
}
return reversed == number;
}
xxxxxxxxxx
#include<iostream>
using namespace std;
int main(){
int number,remainder,sum=0,temp;
cin>>number;
temp=number;
while(number>0){
remainder=number%10;
sum=(sum*10)+remainder;
number=number/10;
}
if(temp==sum){
cout<<temp<<" is a palindrome"<<endl;
}
else{
cout<<temp<<" is not a palindrome"<<endl;
}
return 0;
}
xxxxxxxxxx
#include <iostream>
using namespace std;
int main()
{
int number;
int remainder = 0;
int reverse = 0;
cout << "Enter a Number: ";
cin >> number;
int temp = number;
while (temp != 0)
{
// Get the last digit of temp
remainder = temp % 10;
// Store the remainder after the initially stored value in reverse
reverse = reverse * 10 + remainder;
// remove the last digit of temp
temp = temp / 10;
}
if (number == reverse)
{
cout << number << " is palindrome. " << endl;
}
else
{
cout << "Not palindrome";
}
return 0;
}