#include<iostream>
using namespace std;
int input;
int n;//用于计算自幂数位数或者输入完备数
int i;//用于计算自幂数
int flag = 0;//用于跳出多重循环
int sum = 0;//用于完备数因子的累加
void menu()
{
cout << "**********************************" << endl;
cout << "***********1. 求自幂数 *********" << endl;
cout << "***********2. 判断完备数 *********" << endl;
cout << "***********3. 退出 *********" << endl;
cout << "**********************************" << endl;
}
int fuc1(int x)
{
x = n;
switch (x)
{
case 1:
cout << "1位数的自幂数有->";
for (i = 1; i < 10; i++)
{
if (i == pow(i % 10, 1))
cout << i << " ";//间隔为一个空格输出
else
continue;
}
break;
case 2:
i = 10;
cout << "2位数的自幂数有->";
do
{
if (i == pow(i % 10, 2) + pow(i / 10, 2))
{
cout << i << " ";
i++;
}
else
{
i++;
continue;
}
} while (i < 100);
break;
case 3:
cout << "3位数的自幂数有->";
for (i = 100; i < 1000; i++)
{
if (i == pow(i / 100, 3) + pow((i % 100 / 10), 3) + pow(i % 10, 3))
cout << i << " ";
else
continue;
}
break;
case 4:
cout << "4位数的自幂数有->";
for (i = 1000; i < 10000; i++)
{
if (i == pow(i/1000,4) + pow(i % 1000/100, 4) + pow((i % 100/10 ), 4) + pow(i % 10, 4))
cout << i << " ";
else
continue;
}
break;
case 5:
cout << "5位数的自幂数有->";
for (i = 10000; i < 100000; i++)
{
if (i ==pow(i/10000,5)+ pow(i%10000 / 1000, 5) + pow(i % 1000 / 100, 5) + pow((i % 100 / 10), 5) + pow(i % 10, 5))
cout << i << " ";
else
continue;
}
break;
default:
{
cout << "输入不符合规范,请重新输入" << endl;
flag = 1;
break;
}
}
return i ,flag ;
}
int fuc2(int y)
{ y = n ;
int m = 0;
sum = 0;
for (m = 1; m < y; m++)
{
if (y % m == 0)
sum += m;
else
continue;
}
return sum ;
}
int main()
{
do
{
menu();
cout << "请输入数字选择:";
cin >> input;
switch (input)
{
case 1:while (1)
{
flag = 0;
cout << "请输入输入5以内的位数:";
cin >> n;
fuc1(n);
cout << endl;
if (flag == 1)
continue;
else
break;
}
break;
case 2:
cout << "请输入一个数字,判读是否为完备数->";
cin >> n;
fuc2(n);
if (sum == n)
cout << n << "是完备数" << endl;
if (sum != n)
cout << n << "不是完备数" << endl;
break;
case 3:flag = 1;
cout << "退出程序" << endl;
break;
default:
cout << "输入无效,请重新输入" << endl;
break;
}
if (flag == 1)
break;
} while (1);
return 0;
}