Check String is Palindrome or not in C++

Google Advertisements

Palindrome Number in C++ GCD of Two Number in C++

Program to Check String is Palindrome or not in C++

A Palindrome String is a String that remains the same when its character are reversed. Like saas, for example: we take saas and reverse it, after revers it is same as original.

Steps to write program

  • Get the string from user.
  • Reverse it.
  • Compare it with the string entered by the user.
  • If both are same then print palindrome
  • Else print not a palindrome.

Program to Check String is Palindrome or not in C++

#include<iostream.h>
#include<conio.h>

void main()
{
int i,j,len,flag=1;
char a[20];
    
cout<<"Enter a string:";
cin>>a;
    
for(len=0;a[len]!='\0';++len);
   
for(i=0,j=len-1;i<len/2;++i,--j)
{
if(a[j]!=a[i])
flag=0;
}
   
if(flag==1)
{
cout<<"\nString is Palindrome";
}
else
{
cout<<"\nString is not Palindrome";
}
getch();
}

Output

Enter a String: saas
String is Palindrome

Check String is Palindrome or not in C++

#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>

void main() 
{ 
char str[10]; 
int i,j,n,flag=0; 
cout<<"Enter any string:"<<endl; 
gets(str); 
n=strlen(str); 
for(i=0,j=n-1;i<=n/2;i++,j--) 
{ 
if(str[i]!=str[j]) 
flag=1; 
break; 
} 
if(flag==1) 
{
cout<<"String is not Palindrome"; 
}
else
{
cout<<"String is Palindrome"; 
}
getch(); 
}

Output

Enter any String: lol
String is Palindrome

Palindrome Number in C++ GCD of Two Number in C++

Google Advertisements

We have more than 5 Groups which have 500000+ Members and some Pages have more than 100000+ members. If you want to post your article on our website/FB Group/FB Page please contact on hitesh.xc@gmail.com or 8076671483

Buy This Ad Space @$50 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 8076671483

Path variable is set for providing path for all Java tools like java, javac, javap, javah, jar, appletviewer which are used in java programming. All these tools are available in bin folders so we set path upto bin folders. Difference between path and classpath in Java

Classpath variable is set for providing a path for predefined Java classes which is used in our application. All classes are available in lib/rt.jar so we set classpath upto lib/rt.jar. Difference between path and classpath in Java

Cloud computing is the on demand availability of computer system resources, especially data storage and computing power, without direct active management by the user. Cloud Computing Tutorial

College Projects Related to Java, AWT, C Projects for College, C++ Projects for College, Android Projects. Download Java C C++ Projects

Download Projects

Adsense Advertisements


Buy This ads Space 8076671483

Buy This Ad Space @$120 per Month, Ad Size 300X600 Contact on: hitesh.xc@gmail.com or 8076671483 Try this Keyword C++ Programs