google.com, pub-4617457846989927, DIRECT, f08c47fec0942fa0 Learn to enjoy every minute of your life.Only I can change my life.: Using power function display armstrong number

Saturday, March 1, 2014

Using power function display armstrong number

#include<iostream.h>
#include<math.h>
int main()
{
int sum,n,temp,rem;
cout<<"The Armstrong number between the range 1 to 500 are : \n"; 
for(int x=1;x<=500;x++)
{
n=x;
sum=0;
temp=n;
do
{
rem=n%10;
n=n/10;
int p;
p=pow(rem,3);
sum=sum+p;
}while(n!=0);
if(sum==temp)
cout<<x<<"\t";
}
cout<<"\t";
return 0;
}

Output:
The Armstrong number between the range 1 to 500 are : 
1      153     370     371     407
 

No comments:

Post a Comment

शिव भोलेनाथ स्तुति

 जय शिवशंकर, जय गंगाधर, करुणा-कर करतार हरे,   जय कैलाशी, जय अविनाशी, सुखराशि, सुख-सार हरे जय शशि-शेखर, जय डमरू-धर जय-जय प्रेमागार हरे,   जय ...