Posted by: Sourav | May 14, 2015

Palindrome in C


#include<stdio.h>
//#include<conio.h>
int main()
{
int i=0;
int j=0;
char s[100]=””;
char r[100]=””;
//clrscr();
printf(“Please enter a string to check\n”);
scanf(“%s”,s);
//gets(s);
printf(“you have entered %s\n”,s);
while(s[i]!=”)
{
i++;
}
printf(“The length of the string is %d\n”,i);
i=i-1;
while(i>=0)
{
r[j]=s[i];
j++;
i–;
printf(“The reverse string is %s\n”,r) ;

}
j–;
i++;
printf(“%d\n”,j);
while(j>=0)
{
if (r[j]==s[j])
{

}
else
{
break;
}
j–;
}
printf(“%d\n”,j);
if(j==-1)
{
printf(“pal\n”);
}
else
printf(“not pal\n”);

//getch();
return 0;
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: