C++ Program To Check Array Is Armstrong Or Not

Problem :- 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. For More Click Here

No Need To Explain Check This C++ Program To Check Number Is Armstrong Or Not Now you Got It

Solution :-

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

Previous Post
Next Post