Friday 18 August 2017

Palindrome Function using C Language

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
****************************************/
Graphical Representation :-

Image of Palindrome


Image of Palindrome

**If you  have any problems with above code please leave in Comment Section and check this website daily for more information and thank you.**

No comments:

Post a Comment

Intent in Kotlin Android Studio

 Hi larnkoders in this post you are going to learn  about, How to make pass to new activity with information or simply go to new activity on...