Problem statement
Write a program to take a string as input and check whether it is palindrome or not.
What is mean by palindrome string or number
A palindrome string is a string that reads the same backward as forward.
For example: madam, racecar, etc.
A palindrome is a number that remains the same when its digits are reversed.
A number is a palindrome if the reverse of that number is equal to the original number.
For example: 16461
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
#include<stdio.h> #include<string.h> int main() { int len=0,i=0; char str1[50] = ""; char str2[50] = ""; printf("Enter the string\n"); scanf("%s",&str1); for(i=0;i<100;i++) { if(str1[i] =='\0') { len=i; break; } } for(i=0;i<len;i++) { str2[i]=str1[(len-1)-i]; } if(!strcmp(str1,str2)) printf("\nstring is palindrome"); else printf("string is not palindrome"); } |
Output
1 2 3 |
Enter the string racecar string is palindrome |
1 2 3 |
Enter the string racecAR string is not palindrome |