Tutorialsrack 23/04/2020 Python
In this Python Program, we will learn how to print Palindrome Numbers from 1 to 100 or between a specific range.
What is Palindrome?
A palindrome is a word, number, phrase, or other sequences of characters that reads the same backward as forward, such as civic or rotator or the number 14241.
A number is a palindrome when we reverse the number and the reversed number is equal to the original number.
Here is the code of the program to print Palindrome Numbers from 1 to 100 or between a specific range.
# Python Program to print Palindrome numbers from 1 to 100
# Take the Input from the User
minValue = int[input["Enter the Minimum Value : "]]
maxValue = int[input["Enter the Maximum Value : "]]
print["Palindrome Numbers between %d and %d are : " %[minValue, maxValue]]
for num in range[minValue, maxValue + 1]:
temp = num
reverse = 0
while[temp > 0]:
Reminder = temp % 10
reverse = [reverse * 10] + Reminder
temp = temp //10
if[num == reverse]:
print["%d " %num, end = ' ']
Enter the Minimum Value : 1
Enter the Maximum Value : 100
Palindrome Numbers between 1 and 100 are :
1 2 3 4 5 6 7 8 9 11 22 33 44 55 66 77 88 99
View Discussion
Improve Article
Save Article
View Discussion
Improve Article
Save Article
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.
Implementation:
C++
#include
using
namespace
std;
int
isPalindrome[
int
n]
{
int
rev = 0;
for
[
int
i = n; i > 0; i /= 10]
rev = rev*10 + i%10;
return
[n==rev];
}
void
countPal[
int
min,
int
max]
{
for
[
int
i = min; i
None
:
for
i
in
range
[minn, maxx
+
1
]:
if
isPalindrome[i]:
print
[i, end
=
" "
]
if
__name__
=
=
"__main__"
:
countPal[
100
,
2000
]
C#
using
System;
class
GFG
{
public
static
int
isPalindrome[
int
n]
{
int
rev = 0;
for
[
int
i = n; i > 0; i /= 10]
{
rev = rev * 10 + i % 10;
}
return
[n == rev] ? 1 : 0;
}
public
static
void
countPal[
int
min,
int
max]
{
for
[
int
i = min; i 0; i /= 10]
{
rev = [[rev*10] + [Math.trunc[i]%10]];
}
return
[n==rev];
}
function
countPal[min, max]
{
for
[
var
i = min; i 0]: dig=n%10 rev=rev*10+dig n=n//10 if[temp==rev]: print["The number is a palindrome!"] else: print["The number isn't a palindrome!"]