Wednesday, August 17, 2011

C++ program to print armstrong numbers between 1 to 1000


Are you looking for the armstrong numbers program in C++? if yes, read up on to know and learn the armstrong numbers program in C++.

What is armstrog number?
An armstrong number is that number whose digits when raised to power 3 and added produce the number itself for example:

153 = 13 + 53 + 33

The following program prints armstrong numbers between 1 to 1000.


#include<iostream.h>
#include<conio.h>
void arm(int);

void main()
{
                for(int i=1;i<=1000;++i)
                {
                 arm(i);
                }
}
void arm(int a)
{
int b,rem,sum=0;
b=a;
     while(a>0)
     {
      rem=a%10;
      sum=sum+(rem * rem * rem);
      a=a/10;
     }
if(sum==b)
cout<<"Armstrong Num "<<b<<"\n";
}

No comments:

Post a Comment