Write a program to Print All Palindrome Numbers Between n and m using While loop in C
Write a program to Print All Palindrome Numbers Between n and m using While loop in C++
Write a program to Print All Palindrome Numbers Between n and m using While loop in Python
Write a program to Print All Palindrome Numbers Between n and m using While loop in PHP
Write a program to Print All Palindrome Numbers Between n and m using While loop in Java
Write a program to Print All Palindrome Numbers Between n and m using While loop in Java Script
Write a program to Print All Palindrome Numbers Between n and m using While loop in C#
Explanation:
Logic
Palindrome Definition:
A number is a palindrome if it reads the same forward and backward.
Reverse the number and compare it with the original.
Steps:
Define a function to check if a number is a palindrome.
Use a for loop to iterate from n to m.
For each number in the range, check if it is a palindrome.
If true, print the number.
Program to Print All Palindrome Numbers Between n and m using While loop
C
C++
Python
PHP
JAVA
Java Script
C#
#include <stdio.h>
int isPalindrome(int num) {
int originalNum = num, reversedNum = 0, remainder;
while (num != 0) {
remainder = num % 10;
reversedNum = reversedNum * 10 + remainder;
num /= 10;
}
return (originalNum == reversedNum);
}
int main() {
int n, m;
printf("Enter the range (n and m) to find palindrome numbers: ");
scanf("%d %d", &n, &m);
int num = n;
while (num <= m) {
if (isPalindrome(num)) {
printf("%d ", num);
}
num++;
}
printf("\n");
return 0;
}
#include <iostream>
using namespace std;
bool isPalindrome(int num) {
int originalNum = num, reversedNum = 0, remainder;
while (num != 0) {
remainder = num % 10;
reversedNum = reversedNum * 10 + remainder;
num /= 10;
}
return (originalNum == reversedNum);
}
int main() {
int n, m;
cout << "Enter the range (n and m) to find palindrome numbers: ";
cin >> n >> m;
int num = n;
while (num <= m) {
if (isPalindrome(num)) {
cout << num << " ";
}
num++;
}
cout << endl;
return 0;
}
def is_palindrome(num):
original_num = num
reversed_num = 0
while num != 0:
remainder = num % 10
reversed_num = reversed_num * 10 + remainder
num //= 10
return original_num == reversed_num
n, m = map(int, input("Enter the range (n and m) to find palindrome numbers: ").split())
num = n
while num <= m:
if is_palindrome(num):
print(num, end=" ")
num += 1
print()
<?php
function isPalindrome($num) {
$originalNum = $num;
$reversedNum = 0;
while ($num != 0) {
$remainder = $num % 10;
$reversedNum = $reversedNum * 10 + $remainder;
$num = (int)($num / 10);
}
return $originalNum == $reversedNum;
}
list($n, $m) = explode(" ", readline("Enter the range (n and m) to find palindrome numbers: "));
$num = $n;
while ($num <= $m) {
if (isPalindrome($num)) {
echo $num . " ";
}
$num++;
}
echo "\n";
?>
import java.util.Scanner;
public class Palindrome {
public static boolean isPalindrome(int num) {
int originalNum = num, reversedNum = 0, remainder;
while (num != 0) {
remainder = num % 10;
reversedNum = reversedNum * 10 + remainder;
num /= 10;
}
return originalNum == reversedNum;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the range (n and m) to find palindrome numbers: ");
int n = sc.nextInt();
int m = sc.nextInt();
int num = n;
while (num <= m) {
if (isPalindrome(num)) {
System.out.print(num + " ");
}
num++;
}
System.out.println();
sc.close();
}
}
function isPalindrome(num) {
let originalNum = num;
let reversedNum = 0;
while (num !== 0) {
let remainder = num % 10;
reversedNum = reversedNum * 10 + remainder;
num = Math.floor(num / 10);
}
return originalNum === reversedNum;
}
let [n, m] = prompt("Enter the range (n and m) to find palindrome numbers: ").split(" ").map(Number);
let num = n;
while (num <= m) {
if (isPalindrome(num)) {
console.log(num);
}
num++;
}
using System;
class Program {
static bool IsPalindrome(int num) {
int originalNum = num, reversedNum = 0, remainder;
while (num != 0) {
remainder = num % 10;
reversedNum = reversedNum * 10 + remainder;
num /= 10;
}
return originalNum == reversedNum;
}
static void Main() {
Console.Write("Enter the range (n and m) to find palindrome numbers: ");
string[] inputs = Console.ReadLine().Split(' ');
int n = int.Parse(inputs[0]);
int m = int.Parse(inputs[1]);
int num = n;
while (num <= m) {
if (IsPalindrome(num)) {
Console.Write(num + " ");
}
num++;
}
Console.WriteLine();
}
}