花了不少时间,还是没写对,谁能帮我写一个啊?
或者帮我改一下这个也好
这是我写的错的程序
或者帮我改一下这个也好
这是我写的错的程序
程序代码:
#include <stdio.h> #include <conio.h> int check(int n[]) { int k; long long sum = 0; for(k = 1; k < 10; k++) { sum = sum + n[k]; //printf("%d %d\n",sum, k); //检查能否被整除 if(sum % k != 0) {return 0;} sum = sum * 10; //printf("%I64d %d\n",sum/10, k); } return 1; } // The answer is: 381654729 int main (void) { int i, k, m, r, s, tmp; int j = 0; int Count = 1; int v[10] = {100,1,2,3,4,5,6,7,8,9}; // The posistion v[0] will never be used //long long a; j = 0; for(i = 1; i <= 10; i++) { if(v[9-j] > v[8-j]) { if(v[9-j] == 9 && j != 0) { //v[8-j] change place with v[9] tmp = v[8-j]; v[8-j] = v[9]; v[9] = tmp; j = 0; } else { tmp = v[9-j]; v[9-j] = v[8-j]; v[8-j] = tmp; j = 0; } while((9-j) <= 7) { // bubbelsorting for(r = 1; r < j; r++) { for(s = j-1; s >= r; s--) { if(v[s] < v[s-1]) { tmp = v[s-1]; v[s-1] = v[s]; v[s] = tmp; } } } } } else { j++; } if(check(v)) { for(k = 1; k < 10; k++) { printf("%d",v[k]); } } for(k = 1; k < 10; k++) { printf("%d",v[k]); } printf("\n\n"); } getch(); }