C language code for palindrome string



               
                                           
                                       A palindrome is a string, integer number or another sequence of characters that reads the same backward as forward, such as madam or racecar or the number 76567. If we read madam from the front or back side then the spelling and pronunciation are same i.e. nayan=nayan. The actual code for the palindrome string is as follows:   



C language code for Palindrome string:

#include <stdio.h>om

#include <string.h>

void main()

{

  char a[100], b[100];

  clrscr();

  printf("Enter a string to check if it is a palindrome:\n");

  gets(a); //to accept the string from user



  strcpy(b,a);  // Copying input string

  strrev(b);  // Reversing the string by inbuild function strrev()



  if (strcmp(a,b)==0)  /* Comparing input string using

  inbuild function strcmp() with the given reverse string*/



  printf("The string is a palindrome.\n");/* when if condition

  is satisfy or true */


  else

    printf("The string is not a palindrome.\n");/* when if condition

    is not satisfy or false */

  getch();

}

------------------------------------------------------------------------------

Output:

Enter a string to check if it is a palindrome:

asdfdsa

The string is a palindrome.
C language code for palindrome string C language code for palindrome string Reviewed by Amit Waghmare on July 23, 2019 Rating: 5

No comments: