Friday 8 July 2016

To find the given sting is palindrome or circular palindrome or not a palindrome

#include<stdio.h>
#include<conio.h>
int first,last,len,palindrome=0,true,flag=0;
char s[100];
// TO CHECK WHETHER THE GIVEN STRING IS PALINDROME 
int ispal(){
last=len-1;
for(first=0;first<len/2;first++){
if(s[first]!=s[last--]){
return 0;
}
}
return 1;
}
// TO CHECK WHETHER THE GIVEN STRING IS CIRCULAR PALINDROME
int pal(int f,int l){
int count=0;
for(;count<len;){
if(f==len) // IF FIRST REACHES THE LAST CHARACTER OF THE             f=0;          STRING..
if(l==-1)  // IF LAST REACHES THE FIRST CHARACTER OF THE
l=len-1;      STRING
if(s[f++]!=s[l--]){
return 0;
}
count++;
}
return 1;
}
//TO PRINT THE CIRCULAR PALINDROME STRING
void print(int ii){
int k;
for(k=0;k<len;k++){
if(ii==len)
ii=0;
printf("%c",s[ii++]);
}
}
//DRIVER PROGRAM
void main(){
int i,j;
clrscr();
scanf("%s",s);
for(len=0;s[len]!='\0';len++);
palindrome=ispal();
if(palindrome==1){
printf("palindrome");
}
else{
j=0;
for(i=1;i<len&&true==0;i++,j++){
true=pal(i,j);
if(true==1){
first=i;
last=j;
flag=1;
}
}
if(flag==1){
printf("%s is a circular palindrome of ",s);
print(first);
}
else
printf("\nNot palindrome");
}
getch();
}

No comments:

Post a Comment