Tuesday, July 26, 2011

Checking whether a String is Palindrome,Complete Source Code


Strings which are read the same, both forward and backward  are called Palindrome Strings eg:malayalam. Palindrome checking is a Common Program for Beginners.The program below can be used to check whether a String is a Palindrome.

 #include<stdio.h>  
 #include<conio.h>  
 #include<string.h>  
 void main()  
 {  
 int i,l,f=0;  
 char a[20];  
 printf("\nEnter the string:");  
 scanf("%s",a);  
 l=strlen(a);  
 for(i=0,l=l-1;a[i]!='\0';i++,l--)  
 {  
 if(a[i]!=a[l])  
 {  
 f=1;  
 break;  
 }  
 }  
 if(f==0)  
 printf("String is palindrome");  
 else  
 printf("String is not palindrome");  
 }  

0 comments:

Post a Comment

Subscribe

The Source Codes Published in this Blog can be used freely for Educational purposes but should not be reproduced on any other Blog or Website without the consent of the author.