解题思路:先将符合条件的数字找出来,放在一个数组里,再来排序。希望对大家要帮助
参考代码:
#include<stdio.h>
int R1(int n)
{
int sum2 = 1;
for (; n > 0; n--)
{
sum2 = sum2 * n;
}
return (sum2);
}
int R2(int n)
{
int sum1 = 0, t = 0;
while (n != 0)
{
t = n % 10;
sum1= sum1+ R1(t);
n = n / 10;
}
return (sum1);
}
int R3(int n)
{
int s = 0;
while (n != 0)
{
s = n % 10;
n = n / 10;
}
return (s);
}
int main()
{
int i, j, a[10], n = 0, t = 0;
for (i = 1; i <= 100000; i++)
{
if (R2(i) == i)
{
a[n] = i;
n++;
}
}
for (i = 0; i <=( n-1); i++)
{
for (j = i + 1; j <= (n-1); j++)
{
if (R3(a[i]) > R3(a[j]))
{
t = a[i];
a[i] = a[j];
a[j] = t;
}
}
}
for (i = 0; i <= (n-1); i++)
printf("%d ", a[i]);
return 0;
}
0.0分
3 人评分