How to write A Program for Armstrong Number.
before to start this program just get the definition of Armstrong number .
like (153=1*1*1+5*5*5+3*3*3).left side value is equal to the right side value then number is called Armstrong number.else number is not Armstrong number
class arm
{
int n;
public: arm();
void display();
};
void arm::arm()
{
cout<<"\n a=";
cin>>n;
}
void arm::display()
{
int sum=0,r;
int a=n;
while(n>0)
{
r=n%10;
n=n/10;
sum=sum+(r*r*r);
}
if(a==sum)
cout<<"armstrong";
else cout<<"not armstrong";
}
void main()
{
arm ob;
clrscr();
ob.display();
getch();
}
before to start this program just get the definition of Armstrong number .
like (153=1*1*1+5*5*5+3*3*3).left side value is equal to the right side value then number is called Armstrong number.else number is not Armstrong number
class arm
{
int n;
public: arm();
void display();
};
void arm::arm()
{
cout<<"\n a=";
cin>>n;
}
void arm::display()
{
int sum=0,r;
int a=n;
while(n>0)
{
r=n%10;
n=n/10;
sum=sum+(r*r*r);
}
if(a==sum)
cout<<"armstrong";
else cout<<"not armstrong";
}
void main()
{
arm ob;
clrscr();
ob.display();
getch();
}
0 comments: