Wednesday, October 19, 2011

Program:To check if a string is a palindrome or not




TO check if a string is a palindrome or not

#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<<"The string is Palindrome"; 
getch(); 
}

Article by
Chief-Editor

He is a tech Enthusiast, an Altruist and calm mentor. He loves to code. He is also a creative graphic designer. Do check out his designfolio @ Jasmeet.asia If you like This post, you can follow me on Twitter.



For Further Reading,
C++ Program

0 comments:

Post a Comment