11/01/2015

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

C++ Program To Check Array Is Armstrong Or Not

Previous Post
Next Post

post written by:

Hi, I’m Ghanendra Yadav, SEO Expert, Professional Blogger, Programmer, and UI Developer. Get a Solution of More Than 500+ Programming Problems, and Practice All Programs in C, C++, and Java Languages. Get a Competitive Website Solution also Ie. Hackerrank Solutions and Geeksforgeeks Solutions. If You Are Interested to Learn a C Programming Language and You Don't Have Experience in Any Programming, You Should Start with a C Programming Language, Read: List of Format Specifiers in C.
Follow Me

0 Comments: