Answers for "armstrong number ex"

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 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

Browse Popular Code Answers by Language