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

Ghanendra Yadav

Ghanendra Yadav

Hello, I Am Ghanendra Yadav Owner of This Blog, I am professional Blogger and Programmer. I Love Programming, Logo Making, And Banner Designing. My Highest Qualification is MCA From NIT Warangal. You Can Find Me On Social Media Through Below Link And If You Have Any Query Related To Programming And Other Subject Comment Below or You Can Mail Me I Will Try To Answer Within 24 Hours Email:- yghanendra@student.nitw.ac.in

Find me on Social Media

Facebook | Twitter | Google+ | RSS Feed

No comments:

Post a Comment