Answers for "which the armstrong number"

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
0

Armstrong numbers

Numbers -- Armstrong numbers
Write a method that can check if a number is Armstrong  number
 
Solution:
public  static  boolean ArmStrongNumber (int  num) {
int a = 0,    b =0,    c= num;
while(num>0){
              a=num%10; 
              num/=10; 
              b=b+(a*a*a);
}
 
if(c==b) {
return true;
}
return false;
}
Posted by: Guest on September-29-2021

Browse Popular Code Answers by Language