Answers for "Armstrong number"

PHP
3

armstrong number

sum of cubes of the digits
Posted by: Guest on November-02-2020
2

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;
Posted by: Guest on January-09-2021
0

armstrong number

#include<stdio.h>
int main()
{ 
      int num ,n,n1,c=0,mul=1,sum=0,r,f,i;
      printf("enter any num: \n");
      scanf("%d",&num);
      n=num;
      n1=num;
      while(n!=0)
      {
          r=n%10;
          c++;
          n=n/10;
     }
     while (num!=0)
     {
         f=num%10;
         mul=1;
         for(i=1;i<=c;i++)
         {
              mul=mul*f;
         }

        sum=sum+mul;
       num=num/10;
     }
     if(n1==sum)
         printf("Armstrong Number");
    else
         printf("Not an Armstrong Number");
  return 0;
}
Posted by: Guest on June-12-2021
1

armstrong numbers

// Armstrong Numbers
1, 2, 3, 4, 5, 6, 7, 8, 9, 153, 370, 371, 407, 1634, 8208, 9474, 54748...
Posted by: Guest on June-13-2021
-1

Armstrong number

<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";}
Posted by: Guest on August-05-2020

Browse Popular Code Answers by Language