Check whether the string is palindrome or not. (Dev C++ Compiler)
//Check whether the entered string is palindrome or not.
#include<iostream>
#include<stdlib.h>
using namespace std;
int main()
{
char str[80];
int l, i, j, flag=1;
cout<<"Enter the string of your choice to check whether its palindrome or not?\n";
cin.getline(str,80);
for(l=0;str[l]!='\0';l++); //get the length of string in variable l;
for(i=0, j=l-1;i<l/2;i++,j--)
{
if(str[i]!=str[j])
{
flag=0;
break;
}
}
if(flag==1)
cout<<"The string : "<<str<<" is a palindrome string.";
else
cout<<"The string : "<<str<<" is not a palindrome string.";
}
#include<iostream>
#include<stdlib.h>
using namespace std;
int main()
{
char str[80];
int l, i, j, flag=1;
cout<<"Enter the string of your choice to check whether its palindrome or not?\n";
cin.getline(str,80);
for(l=0;str[l]!='\0';l++); //get the length of string in variable l;
for(i=0, j=l-1;i<l/2;i++,j--)
{
if(str[i]!=str[j])
{
flag=0;
break;
}
}
if(flag==1)
cout<<"The string : "<<str<<" is a palindrome string.";
else
cout<<"The string : "<<str<<" is not a palindrome string.";
}
No comments
Post your comments