Search
 
SCRIPT & CODE EXAMPLE
 

CPP

c++ check palindrome

#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;
}
Comment

check if a string is palindrome cpp

// 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;

}
Comment

palindrome checker in c++

#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;
}
Comment

Palindrome String solution in c++

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;
	}

};
Comment

how to check string is palindrome or not by user input using c or c++

#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;

}
Comment

check if palindrome

function isPalindrome(str) {
  str = str.toLowerCase();
  return str === str.split("").reverse().join("");
}
Comment

check if string is a palindrome

<script>
  // function that check str is palindrome or not
  function check_palindrome( str )
  {
    let j = str.length -1;
    for( let i = 0 ; i < j/2 ;i++)
    {
      let x = str[i] ;//forward character
      let y = str[j-i];//backward character
      if( x != y)
      {
        // return false if string not match
        return false;
      }
    }
    /// return true if string is palindrome
    return true;
     
  }
 
  //function that print output is string is palindrome
  function is_palindrome( str )
  {
    // variable that is true if string is palindrome
    let ans = check_palindrome(str);
    //condition checking ans is true or not
    if( ans == true )
    {
      console.log("passed string is palindrome ");
    }
    else
    {
      console.log("passed string not a palindrome");
    }
  }
  // test variable
  let test = "racecar";
  is_palindrome(test);
</script>
Comment

Checking String Palindrome

int main()
{
    char str1[20], str2[20];
    int i, j, len = 0, flag = 0;
    cout << "Enter the string : ";
    gets(str1);
    len = strlen(str1) - 1;
    for (i = len, j = 0; i >= 0 ; i--, j++)
        str2[j] = str1[i];
    if (strcmp(str1, str2))
        flag = 1;
    if (flag == 1)
        cout << str1 << " is not a palindrome";
    else
        cout << str1 << " is a palindrome";
    return 0;
}
Comment

Checking String Palindrome

int main()
{
    char str1[20], str2[20];
    int i, j, len = 0, flag = 0;
    cout << "Enter the string : ";
    gets(str1);
    len = strlen(str1) - 1;
    for (i = len, j = 0; i >= 0 ; i--, j++)
        str2[j] = str1[i];
    if (strcmp(str1, str2))
        flag = 1;
    if (flag == 1)
        cout << str1 << " is not a palindrome";
    else
        cout << str1 << " is a palindrome";
    return 0;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: declaring 2d dynamic array c++ 
Cpp :: create a 2d vector in c++ 
Cpp :: migration meaning 
Cpp :: hello world program in c++ 
Cpp :: joins in mysql use sequelize 
Cpp :: how to sort a string alphabetically in c++ 
Cpp :: Count Prefix of a Given String solution leetcode 
Cpp :: Pyramid pattren program in C++ 
Cpp :: check if set contains element c++ 
Cpp :: how to code string to int converter c++ 
Cpp :: C++ Volume of a Cylinder 
Cpp :: how to initialize a vector of pairs in c++ 
Cpp :: convert letters to uppercase in c++ 
Cpp :: sorting vector elements c++ 
Cpp :: c++ pass array to a function 
Cpp :: inline in class in C++ 
Cpp :: c++ input 
Cpp :: Program To Calculate Number Power Using Recursion In C++. The power number should always be positive integer. 
Cpp :: reverse sort a vector 
Cpp :: c elif 
Cpp :: max two numbers c++ 
Cpp :: c plus plus 
Cpp :: c++ float and double 
Cpp :: how to remove first element from vector c++ 
Cpp :: maxheap cpp stl 
Cpp :: passing structure to function in c++ example 
Cpp :: polymorphism in c++ 
Cpp :: visual studio cpp compiler 
Cpp :: vector from angle 
Cpp :: c++ program to print odd numbers using loop 
ADD CONTENT
Topic
Content
Source link
Name
6+5 =