Monday, March 31, 2014

C++ Program to find whether the number is Armstrong or not

C++ Program to find whether the number is Armstrong or not

#include<iostream.h>
#include<conio.h>
class amstrong
{
int n,nd,n2,n3,an,re,re1;
public:
void inputnumb()
{
cout<<"Program to find Amstrong Number\n";
cout<<"Enter the number\n";
cin>>n;
}
void no_digit()
{
n2=n;
nd=0;
do
{
n2=n2/10;
nd++;
}
while(n2!=0);
}
void calculation()
{
an=0;
n3=n;
do
{
int i;
re=n3%10;
re1=re;
for(i=0;i<nd-1;i++)
re=re*re1;
an=an+re;
n3=n3/10;
}
while(n3!=0);
}
void output()
{
cout<<"Entered number is of "<<nd<<" digits\n";
if(n==an)
cout<<"Number is Amstrong number";
else
cout<<"Number is not Amstrong number";
}
};
void main()
{
clrscr();
amstrong a;
a.inputnumb();
a.no_digit();
a.calculation();
a.output();
getch();
}

No comments:

Post a Comment