C Programs:
(i) Using string functions:
#include<stdio.h> #include<string.h> #include<conio.h> void main() { char a[100],b[100]; printf("Enter the string to check if palindrome or not\n"); gets(a); strcpy(b,a); strrev(b); if(strcmp(a,b)==0) printf("\nEntered string is palindrome"); else printf("\nEntered string is not palindrome"); getch(); }
(ii) Comparing Character by Character
#include<string.h> #include<stdio.h> #include<conio.h> void main() { int len,i; char a[100]; printf("Enter the string to check whether it is palindrome or not\n"); gets(a); len=strlen(a); for(i=0;i<len/2;i++) { if(a[i]!=a[len-i-1]) break; } if(i==len/2) printf("\nEntered string is palindrome"); else printf("\nEntered string is not palindrome"); getch(); }
No comments:
Post a Comment