MY OWN PROPER EXPLAINATION ABOUT THE CONCEPT OF PALINDROME NUMBER AND I WILL ALSO SHOW HOW TO CHECK WHETHER A NUMBER A PALINDROME IS NOT
MY OWN PROPER EXPLAINATION ABOUT THE CONCEPT OF PALINDROME NUMBER AND I WILL ALSO SHOW HOW TO CHECK WHETHER A NUMBER A PALINDROME IS NOT
Today, I am going to explain about the concepts of about palindrome number like I will explain you all what is actually a palindrome number. Then I will also show you all how to check whether a number is palindrome or not.
So, guy's without wasting any time, just let's jump deep dive into the concepts of what is actually a palindrome number.
So, guy's palindrome number is nothing but it a number which remains the same while making the number opposite that is you can say while making the number reverse. Which means if any make any number opposite (reverse), the number will remain the same and there won't be any change in the number. This is called palindrome. For example like if I take a number 585 and I reverse that number 585 then 585 number remains the same. This is called palindrome number.
Now coming to the code explanation. Here I have initialise $number within a function Palindrome. Suppose that number I have taken as 585 only and then I have initialise that $number i.e. 585 within a variable $temp. Then I have taken another variable as $new which I have initialise as 0. Then I have used while loop where I have used floor() function. Now you can ask me what is function of floor() function. Very good question. floor() function is basically used to round the number down to it's nearest integer. Or rather you can say to reduce the number to it's lowest whole number values. And within while loop I have kept floor($temp), then I have taken another vaiable $k where I have done $temp%10 and here $temp is 585 as because within $temp I have kept $number which I have initialise as 585 i.e. 585%10 where $k will return the remainder i.e. 5, and then I have taken "$new=($new*10)+$k;" and "$temp=$temp/10;" . After that I have used the if condition where I am checking $new is equal to equal to $number then it will return 1 i.e. true otherwise it will return 0 i.e. false. Then I ahev taken one variable $num-585 which I am checking within a if condition i.e. "if (Palindrome($num))" then the number will be palindrome otherwise the number will not be palindrome.
CODE OF CHECKING A PALINDROME NUMBER =>
IT IS A PALINDROME NUMBER =>
<?php
function Palindrome($number)
{
$temp=$number;
$new=0;
while (floor($temp)) {
$k=$temp%10;
$new=($new*10)+$k;
$temp=$temp/10;
}
if ($new==$number) {
return 1;
}
else{
return 0;
}
}
$num=585;
if (Palindrome($num)) {
echo "The number is palindrome ".$num;
}
else{
echo "The number is not palindrome ".$num;
}
?>
OUTPUT OF IT IS A PALINDROME NUMBER =>
IT IS NOT A PALINDROME NUMBER =>
<?php
function Palindrome($number)
{
$temp=$number;
$new=0;
while (floor($temp)) {
$k=$temp%10;
$new=($new*10)+$k;
$temp=$temp/10;
}
if ($new==$number) {
return 1;
}
else{
return 0;
}
}
$num=529;
if (Palindrome($num)) {
echo "The number is palindrome ".$num;
}
else{
echo "The number is not palindrome ".$num;
}
?>
OUTPUT OF IT IS NOT A PALINDROME NUMBER =>
Comments
Post a Comment