Answers for "Which is Armstrong number?"

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

Browse Popular Code Answers by Language