Strange numbers printing cpp implementation
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
class strange
{ private:
int i,n,d,sum,temp;
public:
void getdata();
void getdisp();
};
void strange::getdata()
{
cout<<"\n\n\t STRANGE NUMBERS\n\n";
cout<<"Upto which number? :
";
cin>>n;
}
void strange::getdisp()
{
cout<<"\n\n Strange numbers upto
"<<n<<" : \n\n";
for(i=1;i<=n;i++)
{ sum=0;
d=0;
temp=i;
while(i>=0)
{ d=temp%10;
sum+=(d*d*d);
temp=temp/10;
}
if(sum==i)
cout<<i<<"\t";
}
}
void main()
{
strange s;
clrscr();
s.getdata();
s.getdisp();
getch();
}
No comments:
Post a Comment