Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Name: checkpalindrome.cpp
- Copyright:
- Author: Mr.Kindle
- Date: 30-11-22 15:14
- Description: This code print all palindromes between a given range and also count the total number of
- palindromes
- */
- #include<iostream>
- #include<math.h>
- using namespace std;
- bool isPalindrome(int );
- int main()
- {
- int max_range,i,count=0;
- printf("Enter the maximum range (more than 10): ");
- scanf("%d",&max_range);
- printf("\n\n");
- /*Now checking each number one by one*/
- for(i=10;i<=max_range;i++)
- if(isPalindrome(i))//or if(ispalindrome == 1)
- {
- printf("%d ",i);
- count++;
- }
- printf("\n\nTotal number of palindrome between 10 & %d is = %d\n\n",max_range,count);
- return 0;
- }//main
- bool 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--;
- }
- if(num == sum)
- return 1;
- else
- return 0;
- }//end of ispalindrome
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement