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:
/*******************************************/
- #include<stdio.h>
- #include<conio.h>
- int main()
- {
- //variables declaration.
- long int num,copy,sum=0;
- int digit;
- //Input the number.
- printf("\n Enter the number:");
- scanf("%d",&num);
- copy=num;
- //calculate the palindrome number.
- while(num>0)
- {
- digit=num%10;
- sum=sum*10+digit;
- num=num/10;
- }
- printf("\n The reverse number is: %d",sum);
- if (copy==sum)\
- //display the palindrome number.
- printf("\n Number is palindrome.");
- else
- printf("\n Number is not palindrome.");
- getch();
- }
- 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