Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Name: palindrome.cpp
- Copyright:
- Author: Mr.Kindle
- Date: 30-11-22 14:59
- Description: This code checks whether a number is palindrome or not.
- */
- #include<iostream>
- #include<math.h>
- using namespace std;
- void isPalindrome(int );
- int main()
- {
- int num;
- cout << "Enter the number:\n";
- cin >> num;
- isPalindrome(num);
- return 0;
- }//main
- void isPalindrome(int num)
- {
- int k,count=0;
- int rem, sum = 0;
- k = num;
- /*Counting total number of digits in the given number*/
- do
- {
- count++;
- k = k/10;
- }
- while(k);// while (num != 0)
- /*K = 0 now hence reassign the value of num to k*/
- k = num;
- /*Reversing the number*/
- while(k)//or while(k!=0)
- {
- rem = k%10;
- sum = sum + rem * pow(10, count - 1);
- k /=10; //shortening the number by one digit
- count--; //to decrease the power of 10 by 1 in the next loop
- }
- if(num == sum)
- printf("\n\nIt is a palindrome ");
- else
- printf("\n\nIt is not a palindrome: ");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement