PHP program palindrome number
palindrome number in php
palindrome number ::-
1] palindrome number is a number which remains same digits reversed.
2] eg ::- number - 24142 is a palindrome number.
on reversing same digits .
1) take a number .
2) Reverse the input digits.
3) compare the two digits.
4) If equal it is digits is palindrome.
palindrome number in php
Example ::-
<?phpfunction palindrome($n){ $number =$n; $sum = 0; while(floor($number)) { $rem = $number % 10; $sum = $sum * 10+$rem; $number = $number/10;
} return $sum;}$input= 1235321;$num= palindrome($input);if($input==$num){echo "$input is a palindrome number";}else { echo "$input is not a palindrome"; }
?> palindrome number in php
<?php
function palindrome($n){
$number =$n;
$sum = 0;
while(floor($number))
{
$rem = $number % 10;
$sum = $sum * 10+$rem;
$number = $number/10;
}
return $sum;
}
$input= 1235321;
$num= palindrome($input);
if($input==$num){
echo "$input is a palindrome number";
}
else {
echo "$input is not a palindrome";
}
?>
Output ::-
· Palindrome Number use in form in php
Example :-
<form method="post">
Enter a number
<input text="text" name="number">
<br></br>
<button type="submit">Check number</button>
</form>
<?php
if($_POST)
{
$number=$_POST['number'];
$reverse=strrev($number);
if($number==$reverse){
echo"The number $number is polindrome";
}
else{
echo"The number $number is not a
polindrom";
}
}
?>
Post a Comment