// Write a C program to check whether the given string is palindrome or not.
// Palindrome should be checked by user defined function.
#include<stdio.h>
#include<conio.h>
#include<string.h>
void palindrome(char []);
void main()
{
char str[20];
clrscr();
printf("Enter string: ");
fgets(str,sizeof(str),stdin);
palindrome(str);
// printf("String is: ");
// puts(str);
getch();
}
void palindrome(char str[])
{
int i,flag=0,len=strlen(str);
// printf("%d\n",len);
for(i=0; i<len-1; i++)
{
if(str[i]!=str[len-2-i])
{
flag=1;
break;
}
}
if(flag)
printf("String is not palindrome.");
else
printf("String is palindrome.");
}
Output:
No comments:
Post a Comment