Armstrong number
temp=n;
while(n>0)
{
r=n%10;
sum=sum+(r*r*r);
n=n/10;
}
if(temp==sum)
printf("armstrong number ");
else
printf("not armstrong number");
return 0; <form method="post">
Enter the Number:
<input type="number" name="number">
<input type="submit" value="Submit">
</form>
<?php
if ($_POST) {
//get the number entered
$number = $_POST['number'];
//store entered number in a variable
$a = $number;
$sum = 0;
//run loop till the quotient is 0
while ($a != 0) {
$rem = $a % 10; //find reminder
$sum = $sum + ($rem * $rem * $rem) || $sum = $rem; //cube the reminder and add it to the sum variable till the loop ends
$a = $a / 10; //find quotient. if 0 then loop again
}
//if the entered number and $sum value matches then it is an armstrong number
if ($number == $sum) {
echo "Yes $number an Armstrong Number";
} else {
echo "$number is not an Armstrong Number";
}
}
//here is another example using while loop
$num=300;
$total=0;
$x=$num;
while($x!=0){
$rem=$x%10;
$total=$total+($rem*$rem*$rem);
$x=$x/10;
}
if($num==$total){
echo "Yes it is an Armstrong number";}
else
{echo "No it is not an armstrong number";} sum of cubes of the digits
Also in PHP:
- codeigniter validation text length
- check sizee string laravel
- change php version ubuntu
- create symbolic in lumen laravel
- cache clear in larave
- automatic date on php
- factoring and seeding in laravel
- check string exist in php
- array count items
- cache;clear laravel
- application of laravel
- Tto upper php
- create random_str laravel
- failed to clear cache laravel
- file could not be downloaded: Unable to find the wrap per "https" - did you forget to enable it when you configured PHP? failed to open stream: No such file or directory
- Your Composer dependencies require the following PHP extensions to be installed: fileinfo
- date increase 1 day
- codeigniter redirect
- date("H:i:s"); is js or php
- check if string contains substring at the start php
- HTML form, add the data into it and submit it to the database by connecting it to MySQL database using PHP.
- change to uppercase php
- clear file cache laravel
- app service provider laravel 191