#include <iostream.h>
#include <conio.h>
#include <math.h>
class armstrong
{
private:
int n1,n2;
public:
void input()
{
cout<<"Enter range(n1 and n2): ";
cin>>n1>>n2;
}
void verify();
};
// :: is scope resolution operator
void armstrong::verify()
{
int sum,rem,num,n;
for(num=n1;num<=n2;num++)
{
n=num;
sum=0;
while(n!=0)
{
rem=n%10;
sum+=pow(rem,3);
n=n/10;
}
if(num==sum)
cout<<num<<endl;
}
}
void main()
{
armstrong a1,b1;
// a1 and b1 are objects of class armstrong.
a1.input();
a1.verify();
b1.input();
b1.verify();
getch();
}
OUTPUT:
No comments:
Post a Comment