程序代码:
#include<stdio.h> int main() { int xiang = 0, rui = 0, sheng = 0, hui = 0, san = 0, xian = 0, qi = 0,yang = 0; int beijia = 0, jia = 0, he = 0; for (xiang = 8; xiang <= 9; xiang++) { for (san = 1; san <= 1; san++) { for (yang = 0; yang <= 1; yang++) { for (hui = 0; hui <= 9; hui++) { for (rui = 0; rui <= 9; rui++) { for (xian = 0; xian <= 9; xian++) { for (sheng = 0; sheng <= 9; sheng++) { for (qi = 0; qi <= 9; qi++) { beijia = xiang * 1000 + rui * 100 + sheng * 10 + hui; jia = san * 1000 + yang * 100 + xian * 10 + rui; he = san * 10000 + yang * 1000 + sheng * 100 + rui * 10 + qi; if (beijia + jia == he) { if ((xiang != rui) && (xiang != sheng) && (xiang != hui) && (xiang != san) && (xiang != xian) && (xiang != qi) && (xiang != yang) && (rui != sheng) && (rui != hui) && (rui != san) && (rui != xian) && (rui != qi) && (rui != yang) && (sheng != hui) && (sheng != hui) && (sheng != san) && (sheng != xian) && (sheng != qi) && (sheng != yang) && (hui != san) && (hui != xian) && (hui != qi) && (hui != yang) && (san != xian) && (san != qi) && (san != yang) && (xian != qi) && (xian != yang) && (qi != yang)) { //printf("%d%d%d%d\n", xiang, rui, sheng, hui); printf("%d%d%d%d\n", san, yang, xian, rui); //printf("%d%d%d%d%d\n", san, yang, sheng, rui, qi); } } } } } } } } } } return 0; }