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

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

Pure VPN Privide Lowest Price VPN Just @ $1.65. Per Month with Non Detected IP Lowest Price Non Detected IP VPN

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

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