RECENTLY PUBLISHED

6/recent/ticker-posts

C++ Program to find all Armstrong Numbers between given range.

                 What is Armstrong Number?

The first thing we must know while learning this program is What is Armstrong Number exactly is?

                                          If we take cube of every digit of that number and add all the cube then we got that same number again.

For Example: 

    The Number 153 is An Armstrong Number.

here if we take 

13  +  53  + 3=  1  +  125  +  27  = 153

As you can see the number 153 is occurred again when we add cube of each digits .

Now , Here you will understand C++ Program for finding all Armstrong Numbers.


#include<iostream>

using namespace std;

int main()

{

  int j,a,r,sum;

  cout<<" Armstrong number are :";

  for(j=1;j<1000;j++)

  {

    sum=0;

    a=j;

    while(a>0)

    {

     r=a%10;

     sum=sum+r*r*r;

     a=a/10;

    }

    if(sum==j)

    cout<<"\n\t\t"<<j;

   }

 return 0;

}


OUTPUT 




Post a Comment

0 Comments