1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| #include <stdio.h>
int pun(int a) { int n, sum = 0; int f[10] = { 6,2,5,5,4,5,6,3,7,6 }; while (a / 10 != 0) { n = a % 10; sum += f[n]; a = a / 10; } sum += f[a]; return sum; } int main() { int sum, i, j,n,m; sum = 0; printf("你有几根火柴?"); scanf_s("%d",&n); for(i=0;i<=1111;i++) for (j = 0; j <= 1111; j++) { m = i + j; if (pun(m) + pun(i) + pun(j) == n - 4) { printf("%d + %d = %d \n", i, j, m); sum++; } } printf("一共有可以拼出 %d 个等式。", sum); getchar(); getchar(); return 0; }
|