Header Ads

Header ADS

Take a string as input and check whether it is a Palindrome. If it is not a palindrome, then add character after the string to convert it into a palindrome.

Take a string as input and check whether it is a Palindrome. If it is not a palindrome, then add

character after the string to convert it into a palindrome.


Code:

#include <stdio.h>

#include<string.h>

int main()

{

  char text[100];

  int begin, middle, end, length = 0;


  gets(text);


  while (text[length] != '\0')

    length++;


  end = length - 1;

  middle = length/2;


  for (begin = 0; begin < middle; begin++)

  {

    if (text[begin] != text[end])

    {

      printf("\n\nNot a palindrome.\n\n");

      printf("palindrome text is:%s",text);

      printf("%s\n\n",strrev(text));

      break;

    }

    end--;

  }

  if (begin == middle)

    printf("Palindrome.\n");


  return 0;

}


No comments

Powered by Blogger.