C Program to find the given string is a palindrome or not.By using an user defined function to reverse the string.

 #include<stdio.h>

#include<string.h>

main()

{

char str[20],ostr[20];

clrscr();

printf("\nEnter a string:\n");

gets(str);

strcpy(ostr,str);

rev(str);

if(strcmpi(ostr,str)==0)

printf("\nThe given string is a Palindrome\n");

else

printf("\nNot a Palindrome\n");

getch();

}

rev(char s[])

{

int n,i,j;

char t;

n=strlen(s);

for(i=0,j=n-1;i<j;i++,j--)

{

t=s[i];

s[i]=s[j];

s[j]=t;

}

}




Output:

  1. Enter a string:

   Malayalam

   The given string is a Palindrome


  1. Enter a string:

College

Not a Palindrome



Post a Comment

Previous Post Next Post