我了个去,简单的程序非要用数组,玩的了,头晕了

#include <iostream>

using namespace std;

class NatureNumble 
{
private:
	int n;
public:
	void setValue (int x);
	int getValue ();
	bool isPrime ();
	void printFactor();
	bool isPerFact();
	bool isReveser(int x);
	bool isDaffodil (int x);
	void printDaffodils ();
};

void main(void)
{
	int x;
    NatureNumble nn;
	nn.setValue (6);
	cout<<nn.getValue()<<(nn.isPrime()?"是":"不是")<<"素数"<<endl;

	nn.setValue(37);
	cout<<nn.getValue()<<(nn.isPrime()?"是":"不是")<<"素数"<<endl;

	nn.setValue(84);
	cout<<nn.getValue()<<"的因子有:";
    nn.printFactor();
     cin>>x;
     nn.setValue (x);

     cout<<nn.getValue()<<(nn.isPrime()?"是":"不是")<<"素数"<<endl;
	cout<<nn.getValue()<<"的因子有:";
    nn.printFactor();
     cout<<nn.getValue()<<(nn.isPerFact()?"是":"不是")<<"完全数"<<endl;
cin>>x;
     cout<<x<<(nn.isReveser(x)?"是":"不是")<<nn.getValue ()<<"的逆向数"<<endl;
     cout<<nn.getValue()<<(nn.isDaffodil (x)?"是":"不是")<<"水仙花数"<<endl<<"小于n的水仙花数为:"<<endl;
     nn.printDaffodils ();
}

void NatureNumble::setValue (int x)
{
	
	n=x;
	cout<<endl;
}

int NatureNumble::getValue ()
{
	return n;
}

bool NatureNumble::isPrime ()
{
	int i;
	for (i=2;i<n;i++)
	{
		if (n%i==0)
		return false ;
		break;
	}
	return true;
}
void NatureNumble::printFactor()
{
	int i;
	cout<<"所有因子为:";
	for (i=1;i<=n;i++)
	{
		if (n%i==0)
			cout<<i<<'\t';
	}
	cout<<endl;
}
bool NatureNumble::isPerFact()
{
	int i,b=0,sum=0;
	int a[100];
	for (i=1;i<n;i++)
	{
		if (n%i==0)
		{
			a[b]=i;
			b++;
		}
	}
	b--;
     
	for (i=0;i<=b;i++)
	{
		sum=sum+a[i];
	}
	if (sum==n)
		return true;
	else 
		return false;
}
bool NatureNumble::isReveser(int x)
{
	int i,sum=0,c=0,a[10];
	for (i=0;x>=1;i++)
	{
		a[i]=x%10;
		x=x/10;
		c++;
	}
	c--;
	for (i=0;i<=c;i++)
	{
		sum=sum*10+a[i];
	}
	if (n==sum)
		return true;
	else
		return false;
}
bool NatureNumble::isDaffodil (int x)
{
	int i,sum1=0,sum2=0,c=0,a[10];

	for (i=0;n>=1;i++)
	{
		a[i]=n%10;
		n=n/10;
		c++;
	}
	c--;
	for(i=c;i>=0;i--)
		sum2=sum2*10+a[i];
	n=sum2;
	
    for (i=0;i<=c;i++)
	{
		sum1=sum1+a[i]*a[i]*a[i];
	}
    if (n==sum1)
		return true;
	else
		return false;
}

void NatureNumble::printDaffodils ()
{int a,b,c,j,sum;
	
	for(j=100;j<=n;j++)
	{
		a=j%10;
		j=j/10;
		b=j%10;
		j=j/10;
		c=j%10;
		sum=a*a*a+b*b*b+c*c*c;
		j=c*100+b*10+a;

        if (j==sum)
		    cout<<j<<'\t';
	
	}
	

}

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值