Answers for "what are armstrong numbers"

2

armstrong numbers

int main(){
    
    int a;
    cin >> a;
    int check = a;
    int sum = 0;
    while(a!=0){
        int rem = a%10;
        sum += pow(rem,3);  //include cmath
        a/=10;
    }

    if(sum==check){
        cout << "armstrong";
    } else {
        cout << "not armstrong";
    }
    return 0;
}
Posted by: Guest on August-19-2021
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
0

armstrong number function

def is_armstrong_number(number: int)-> bool:
    arm = str(number)
    lenght = len(arm)
    sum = 0
    for digit in arm:
        sum += int(digit)**lenght
    return sum == number
Posted by: Guest on June-01-2021
0

How do you calculate Armstrong number in maths?

import java.util.Scanner;  
import java.lang.Math;  
public class one    //ArmstsrongNumberExample  
{  
//function to check if the number is Armstrong or not  
static boolean isArmstrong(int n)   
{   
int temp, digits=0, last=0, sum=0;   
//assigning n into a temp variable  
temp=n;   
//loop execute until the condition becomes false  
while(temp>0)    
{   
temp = temp/10;   
digits++;   
}   
temp = n;   
while(temp>0)   
{   
//determines the last digit from the number      
last = temp % 10;   
//calculates the power of a number up to digit times and add the resultant to the sum variable  
sum +=  (Math.pow(last, digits));   
//removes the last digit   
temp = temp/10;   
}  
//compares the sum with n  
if(n==sum)   
//returns if sum and n are equal  
return true;      
//returns false if sum and n are not equal  
else return false;   
}   
//driver code  
public static void main(String args[])     
{     
int num;   
Scanner sc= new Scanner(System.in);  
System.out.print("Enter the limit: ");  
//reads the limit from the user  
num=sc.nextInt();  
System.out.println("Armstrong Number up to "+ num + " are: ");  
for(int i=0; i<=num; i++)  
//function calling  
if(isArmstrong(i))  
//prints the armstrong numbers  
System.out.print(i+ ", ");  
}   
}
Posted by: Guest on July-10-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

Browse Popular Code Answers by Language