Answers for "armstrong numbers example"

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

Browse Popular Code Answers by Language