参考代码:
#include<stdio.h> int factorial(int molecule){ int product =1; for(int i=1; i<=molecule; i++){ product *= i; } return product; //0的阶乘是1 } int split(int sample){ int sum=0; while(sample!=0){ sum += factorial(sample%10); sample /= 10; } return sum; } void arrange(int disoder[], int subscript){ int gist[20]={0}; for(int i=0; i<subscript; i++){ gist[i] = disoder[i]; while(gist[i]>=10){ gist[i] /=10; } } int avatar1, avatar2; for(int i=0; i<subscript; i++){ for(int j=subscript-1; j>i; j--){ if(gist[j]<gist[j-1]){ avatar1 = gist[j-1]; gist[j-1] = gist[j]; gist[j] = avatar1; avatar2 = disoder[j-1]; disoder[j-1] = disoder[j]; disoder[j] = avatar2; } } } for(int i=0; i<subscript; i++){ printf("%d ", disoder[i]); } } int main(){ int sum; int store[20]; int index=0; for(int i=1; i<=100000; i++){ sum = 0; sum = split(i); if(i==sum){ store[index] = i; index++; } } arrange(store, index); return 0; }
0.0分
0 人评分