How to write armstrong number program in c++ with source code.
Examples of armstrong number in c++.
How to write A Program for 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();
}
Examples of armstrong number in c++.
How to write A Program for 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: