Write a c program to check given string is palindrome number or not





#include<string.h>
#include<stdio.h>
int main(){
  char *str,*rev;
  int i,j;
  printf("\nEnter a string:");
  scanf("%s",str);
  for(i=strlen(str)-1,j=0;i>=0;i--,j++)
      rev[j]=str[i];
      rev[j]='\0';
  if(strcmp(rev,str))
      printf("\nThe string is not a palindrome");
  else
      printf("\nThe string is a palindrome");
  return 0;
}




Definition of Palindrome string:

A string is called palindrome if it symmetric. In other word a string is called palindrome if string remains same if its characters are reversed. For example: asdsa
If we will reverse it will remain same i.e. asdsa

Example of string palindrome:  a,b, aa,aba,qwertrewq etc.






10. Write a c program to add two numbers without using addition operator.
11. Write a c program to subtract two numbers without using subtraction operator.
15. Write a c program to solve quadratic equation.
18. Write a c program which passes structure to function.
28. Write a c program which takes password from user.
29. Write a scanf function in c which accept sentence from user.
30. Write a scanf function in c which accept paragraph from user.

14 comments:

Anonymous said...

here in the above program

char str[10],rev[10];

its cannot be pointer as it is holding the array length

Anonymous said...

thnx for d programs.

Anonymous said...

can any1 explain dis program in detail

Anonymous said...

wat about this..

void checkpalindrome(char* inString)
{
int i, j;
int len = strlen(inString);
for(i = 0, j = strlen(inString)-1; i > len\2 && j > len\2; i++, j--)
{
if(inString[i] != inString[j])
break;
}
if(i == len/2 && j == len\2)
printf("Palindrome\n");
else
printf("Not palindrome\n");
}
}

Anonymous said...

i got output thank u so much

Dhruv said...

I find my answer thank u

dhamiii said...

ye program chalega hi nhiiiiiiiiiiii

Anand said...

There is one more approach to solve the above problem.
The iterations of this program is half of the above mentioned solution.

#include
#include
main()
{
char str[25];
int i, j, isPalindrome = 1;
scanf("%s",str);
for(j = 0, i = strlen(str)-1; j <= i; j++, i--)
{
if(str[j] != str[i])
{isPalindrome = 0; break;}
}
if(isPalindrome)
printf("%s is pallindrome",str);
else
printf("This is not pallindrome");
}

Unknown said...


#include
#include
#include

int main()
{
char s[50], r[50]={'\0'};
int i,l = 0, f = 0;


printf("Enter a string\n");
gets(s);

for (i=0; s[i] != '\0'; i++)
{
l++;
}

for (i=l-1; i >= 0 ; i--)
{
r[l-i-1] = s[i];
}



for (i=0; i < l ; i++)
{
if (r[i] == s[i])
f = 1;
else
f = 0;
}

if (f == 1)
printf ("%s is a palindrome\n", s);
else
printf("%s is not a palindrome\n", s);
return 0;

}

TechRaja said...

#include
#include
#include
void mai()
{
char a[20],b[20];
clrscr();
printf("\n\n\n\t\t\t Enter the String \n");
gets(a);
strcpy(b,a);
strrev(b);
if(strcmp(a,b)==0);
{
printf("\n\t\t\t\t given string is Palindrome\n");
}
else
{
printf("\n\t\t\t\t given string is not a Palindrome\n");
}
getch();
}

Unknown said...

this is the fully friendly site of c programming...... thanks all over frinds and c-question organization

Anonymous said...

and what finding symmetric word ,its place at string?

Vinu Thomas said...

Six different easy ways to find whether a string or number is palindrome or not in C Programming
http://www.waytosmart.com/tutorials/c-programming/six-different-easy-ways-to-find-whether-a-string-or-number-is-palindrome-or-not-in-c-programming.php

Unknown said...

here we are not allocating any specific memory for to store that strings.how it possible to get the string.