C program to check whether input string is palindrome or not
#include<stdio.h>
#include<conio.h>
#include<string.h>
main()
{
char word[30],word1[30];
printf("Enter any string\n");
scanf("%s",word);
strcpy(word1,word);
if(strcmp(word1,strrev(word))==0)
{
printf("%s is palindrome string",word);
}
else
{
printf("%s is not a palindrome string ",word);
}
getch();
}
Another method:
#include <stdio.h>
#include<conio.h>
#include <string.h>
int main()
{
char s[100];
int i, len, f;
f = 0;
printf("Enter any String : \n");
gets(s);
len = strlen(s);
for(i = 0; i < len; i++)
{
if(s[i] != s[len - i - 1])
{
f = 1;
break;
}
}
if(f == 0)
{
printf("%s is a Palindrome String", s);
}
else
{
printf("%s is Not a Palindrome String", s);
}
getch();
}
No comments:
Post a Comment