Problem Statement
Write a c program to check weather a sting is palindrome or not
#include<stdio.h>
int main()
{
char b[54];
int i,n,flag=1;
printf("enter the array and press enter in the end\n");
i=n=0;
do
{
b[i]=getchar();
i++;
}
while(b[i-1]!='\n');
printf("i=%d ",i);
do
{
printf("i=%d i-n-2=%d\n",i,i-n-2);
if(b[n]==b[i-n-2])
{ n=n+1;}
else
{
flag=0;
break;
}
}
while(n<(i-n));
if(flag==0)
{printf("not a palindrome \n");}
else
{
printf("yes this is palindrome \n");
}
return 0;
}
No comments:
Post a Comment