WAP to enter 10 numbers in an
array and print only the palindromic
no. A palindromic number is a number whose reverse is same as the no itself. For example 343 is a palindromic number
Answers
Answer:
Program to print all palindromes in a given range
Given a range of numbers, print all palindromes in the given range. For example if the given range is {10, 115}, then output should be {11, 22, 33, 44, 55, 66, 77, 88, 99, 101, 111}
We can run a loop from min to max and check every number for palindrome. If the number is a palindrome, we can simply print it.
#include<iostream>
using namespace std;
// A function to check if n is palindrome
int isPalindrome(int n)
{
// Find reverse of n
int rev = 0;
for (int i = n; i > 0; i /= 10)
rev = rev*10 + i%10;
// If n and rev are same, then n is palindrome
return (n==rev);
}
// prints palindrome between min and max
void countPal(int min, int max)
{
for (int i = min; i <= max; i++)
if (isPalindrome(i))
cout << i << " ";
}
// Driver program to test above function
int main()
{
countPal(100, 2000);
return 0;
}
Explanation:
I hope it is useful for you