Palindrome function

Q. Write a C program to check whether a string is palindrome or not using function.

Ans.

/*Program to check whether a string is palindrome or not using function*/
#include<stdio.h>
#include<conio.h>
char string_palin(char str[]);
int main()
{
 char ch[30];
 printf("Enter string : ");
 gets(ch);
 if(string_palin(ch))
    printf("Entered string Palindrome");
 else
    printf("Entered string not Palindrome");
 return 0;
}

/*function for palindrome*/
char string_palin(char str[])
{
 int i,j;
 for(i=0; str[i]!=NULL; i++);
 for(j=0,i--; j<=i; )
 {
   if(str[i]==str[j])
   {
      i--;
      j++;
   }
  else
      break;
 }
 if(j>i)
    return(1);
 else
    return(0);
}


/*****************Output****************

Enter string : SHAREMARKET
Entered string not Palindrome

Enter string : MALAYALAM 
Entered string Palindrome

****************************************/

You might also like:

  1. What is Palindrome
  2. Check palindrome using pointer

Comments