Q:

C++ Program To Check Array Is Armstrong Or Not

0

Write A C++ Program To Check  An Array Is Armstrong Or Not .Means How Many Elements in Array is Armstrong

Logic :- What Is Armstrong  Number ?

An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is equal to the number itself. For example, 371 is an Armstrong number since 3**3 + 7**3 + 1**3 = 371. Write a program to find all Armstrong number in the range of 0 and 999. 

 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include<iostream>
using namespace std;
int main()
{
  int a[100],i,n;
  
 cout<<"Enter the size of array\n";
  cin>>n;
 
  cout<<"Enter the element\n";
  for(i=0;i<n;i++)
  {
    cin>>a[i];
  }

  for(i=0;i<n;i++)
 {
  int k=0,rem=0,sum=0;
    k=a[i];
    while(k!=0)
    {
      rem=k%10;
      sum=sum+rem*rem*rem;
      k=k/10;
    }
    if(sum==a[i])
     cout<<a[i]<<"\t Is ArmStrong\n";
    else
     cout<<a[i]<<"\t Is Not ArmStrong\n";
     
  }

 return 0;
}

 

Output:

Enter the size of array

6

Enter the element

0

1

153

370

407

600

0 Is ArmStrong

1 Is ArmStrong

153 Is ArmStrong

370 Is ArmStrong

407 Is ArmStrong

600 Is Not ArmStrong

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now