依次输出电话号码对应的所有字母组合。 /* ============================================================================ Name : telephoneNum.c Author : qibaoyuan Version : Copyright : Your copyright notice Description : Hello World in C, Ansi-style ============================================================================ */ #include <stdio.h> #include <stdlib.h> #include <string.h> char c[10][10] = { "", "", "ABC", "DEF", "GHI", "JKL", "MNO", "PQRS", "TUV", "WXYZ" }; int total[10] = { 0, 0, 3, 3, 3, 3, 3, 4, 3, 4 }; int main(void) { int i = 0; int number[] = { 2, 3, 4, 5, 6, 7, 8, 9 }; int n = sizeof(number) / sizeof(number[0]); int *answer = (int*) calloc(sizeof(int), n); while (1) { for (i = 0; i < n; ++i) { printf("%c", c[number[i]][answer[i]]); } printf("/n"); int k = n - 1; while (k >= 0) { if (answer[k] < total[number[k]] - 1) { answer[k]++; break; } else { answer[k] = 0; k--; } } if (k < 0) break; } return EXIT_SUCCESS; }