#include <stdio.h>
int main()
{
int a, b, c,d,e,arr[100000],l=-1,w=-1;
int temp1 = 0, temp2 = 0, temp3 = 0, temp4 = 0, temp5 = 0;
for (int i = 1; i <=99999; i++)
{
a = i / 10000;
b = i % 10000 / 1000;
c = i % 1000 / 100;
d = i % 100 / 10;
e = i % 10;
if (a != 0) //五位数
{
temp1 = 1;
temp2 = 1;
temp3 = 1;
temp4 = 1;
temp5 = 1;
for (int j = 1; j <= a; j++)
{
temp1 *= j;
}
for (int k = 1; k <= b; k++)
{
temp2 *= k;
}
for (int h = 1; h <= c; h++)
{
temp3 *= h;
}
for (int p = 1; p <= d; p++)
{
temp4 *= p;
}
for (int q = 1; q <= e; q++)
{
temp5 *= q;
}
}
else if (b != 0) //四位数
{
temp2 = 1;
temp3 = 1;
temp4 = 1;
temp5 = 1;
int temp1 = 1, temp2 = 1, temp3 = 1, temp4 = 1, temp5 = 1;
for (int k = 1; k <= b; k++)
{
temp2 *= k;
}
for (int h = 1; h <= c; h++)
{
temp3 *= h;
}
for (int p = 1; p <= d; p++)
{
temp4 *= p;
}
for (int q = 1; q <= e; q++)
{
temp5 *= q;
}
}
else if (c != 0) //三位数
{
temp3 = 1;
temp4 = 1;
temp5 = 1;
for (int h = 1; h <= c; h++)
{
temp3 *= h;
}
for (int p = 1; p <= d; p++)
{
temp4 *= p;
}
for (int q = 1; q <= e; q++)
{
temp5 *= q;
}
}
else if (d != 0) //两位数
{
temp4 = 1;
temp5 = 1;
for (int p = 1; p <= d; p++)
{
temp4 *= p;
}
for (int q = 1; q <= e; q++)
{
temp5 *= q;
}
}
else //一位数
{
temp5 = 1;
for (int q = 1; q <= e; q++)
{
temp5 *= q;
}
}
if (temp1 + temp2 + temp3 + temp4 + temp5 == i)
{
arr[++l] = i;
}
}
//按字典顺序输出
for (int z = 1; z <= 9; z++)
{
for (int i = 0; i <= l; i++)
{
a = arr[i] / 10000;
b = arr[i] % 10000 / 1000;
c = arr[i] % 1000 / 100;
d = arr[i] % 100 / 10;
e = arr[i] % 10;
if ((a == 0 && b == 0 && c == 0 && d == 0 && e == z) || (a == 0 && b == 0 && c == 0 && d == z) || (a == 0 && b == 0 && c == z) || (a == 0 && b == z) || (a == z))
{
++w;
if (w == 0)
{
printf("%d", arr[i]);
}
else
{
printf(" %d", arr[i]);
}
}
}
}
printf("\n");
system("pause");
return 0;
}
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题8.5 (C语言代码)浏览:562 |
1051(奇了怪了)浏览:747 |
C语言程序设计教程(第三版)课后习题8.2 (C语言代码)浏览:1109 |
整除的尾数 (C语言代码)浏览:856 |
C语言程序设计教程(第三版)课后习题5.4 (C语言代码)浏览:487 |
1202题解浏览:690 |
C语言程序设计教程(第三版)课后习题1.5 (C++代码)浏览:419 |
哥德巴赫曾猜测 (C语言代码)浏览:778 |
P1001 (Java代码)浏览:740 |
C语言训练-阶乘和数* (也是笨办法,但是思路好理解),新手写的写的不好请见谅浏览:1496 |