Problem:    Write a function that checks whether a given string is Palindrome or not.Use this function to find whether the string entered by user is Palindrome or not.


What is palindrome: A palindrome is a word, number, phrase, or other sequence of characters which reads the same backward as forward, such as madam, racecar. There are also numeric palindromes, including date/time stamps using short digits 11/11/11 11:11 and long digits 02/02/2020.Source

  • Source Code:

/*******************************************/

  1. #include<stdio.h>
  2. #include<conio.h>
  3. int main()
  4. {
  5.                //variables declaration.
  6.                long int num,copy,sum=0;
  7.                int digit;
  8.               
  9.                //Input the number.
  10.                printf("\n Enter the number:");
  11.                scanf("%d",&num);
  12.                copy=num;
  13.               
  14.                //calculate the palindrome number.
  15.                while(num>0)
  16.                {
  17.                               digit=num%10;
  18.                               sum=sum*10+digit;
  19.                               num=num/10;
  20.                }
  21.                printf("\n The reverse number is: %d",sum);
  22.                if (copy==sum)\
  23.               
  24.                //display the palindrome number.
  25.         printf("\n Number is palindrome.");
  26.     else
  27.         printf("\n Number is not palindrome.");
  28.     getch();
  29. }






  • Output:

 1.        Enter the number:25752

            The reverse number  is: 25752

            Number is palindrome. 

 2.       Enter the number:152

           The reverse number is: 251

           Number is not palindrome.


0 comments:

Post a Comment