Write a C program to check given string is palindrome or not using pointers?

Showing Answers 1 - 6 of 6 Answers

baseersd

  • Jan 7th, 2008
 

#include<stdio.h>

int Ispalindrome(char* str)
{
     int i,len;
    len = strlen(str);
    for(i = 0; i < len / 2; i++)
    {
          if( *(str +i ) != *(str + len - i - 1) )     
              return 0;    
    }
    return 1;
}
int main()
{
    char string[20]="";
    printf("Enter the string ::");
    gets(string);
    if( Ispalindrome(string))
        printf("n%s is a palindromen",string);
    else
        printf("n%s is not a palindromen",string);
 system("pause");    
}

  Was this answer useful?  Yes

aks3937

  • Aug 24th, 2009
 

#include<stdio.h>
#include<conio.h>
void main()
{
int i,flag=0,k,l,m,n;
char str[100];
clrscr();
printf("enter the string n");
scanf("%s",str);
l=strlen(str);
printf("%d",l);
l=l-1;
i=0;
while(strcmp(str[i],str[l])==0)
{
if(i+1==l)
{
printf("its a palindromen");
flag=1;
break;
}
i++;
l--;
if(i==l&&(strcmp(str[i],str[l])==0))
{
printf("its a palindromen");
flag=1;
break;
}
}
if(flag==0)
printf("its not a palindromen");
getch();
}

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions