Answers for "armstrong number 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
1

armstrong number in c

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int cube(int a)
{
    int c;
    c =  a*a*a;
    return c;
}

int armnum(int *a)
{
    int x = *a, n = 0, rem, r = 0;
    while (x != 0) {
        x /= 10;
        n++;
    }
    x = *a;
    while (x != 0) {
        rem = x % 10;
        r += cube(rem);
        x /= 10;
    }
    if(r == *a){
        return 1;
    }
}

int main()
{
    int a, y;
    scanf("%d", &a);
    y = armnum(&a);
    if(y == 1){
        printf("It is an Armstrong number.");
    }
    else{
        printf("It is not an Armstrong number.");
    }
}
Posted by: Guest on August-26-2020
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

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