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.

12 comments:

  1. here in the above program

    char str[10],rev[10];

    its cannot be pointer as it is holding the array length

    ReplyDelete
  2. thnx for d programs.

    ReplyDelete
  3. can any1 explain dis program in detail

    ReplyDelete
  4. 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");
    }
    }

    ReplyDelete
  5. i got output thank u so much

    ReplyDelete
  6. I find my answer thank u

    ReplyDelete
  7. ye program chalega hi nhiiiiiiiiiiii

    ReplyDelete
  8. 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");
    }

    ReplyDelete

  9. #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;

    }

    ReplyDelete
  10. #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();
    }

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

      Delete