/* * comb * * A very slow way to compute the values of Pascal's triangle * Usage: comb * comb 4 * 1 4 6 4 1 */ #include int C(int i, int j) { if (0 == j) return 1; if (i == j) return 1; if (i < 0) return 0; if (j < 0) return 0; return C(i-1, j-1) + C(i-1, j); } int main (int argc, char **argv) { int row = 0; int j = 0; if (argc != 2) { printf("Usage: %s row\n", argv[0]); exit(1); } row = atoi(argv[1]); if (row < 0) { printf("Usage: enter positive integer %d\n", row); exit(1); } for (j = 0; j <= row; j++) { /* printf("\tC(%d, %d) = %d", row, j, C(row, j)); */ printf("\t%d", C(row, j)); } printf("\n"); }