Saturday, March 1, 2014

C++ program to display armstrong number between 1 to 500

C++ pogram to display armstrong number between 1 to 500


#include<iostream.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;
sum=sum+rem*rem*rem;
}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

Featured posts

What is the future of the new generation?

What is the future of the new generation? The future of the new generation is exciting and uncertain. With rapid advancements in technology,...

Popular posts