#if defined(__STDC__) && !defined(__HIGHC__) #include #endif #include #include main(void){ int a; /* first digit */ int b; /* second digit */ int c; /* third digit */ int d; /* fourth digit */ int e = 1; /* first digit */ int f = 1; /* second digit */ int g = 1; /* third digit */ int h = 1; /* fourth digit */ int i = 3; /* first counter */ int j = 3; /* second counter */ int k = 3; /* third counter */ int l = 3; /* fourth counter */ int n = 1; /* counter for displaying output */ int z = 0; /* too many numbers flag */ int p = 0; /* wait until entry is correct */ double v, w, x, y; /* fun with divison */ double r, s, t, u; int q; /* input variable */ /* get the 4 digit number */ while (p <= 0 ){ printf("Enter the last four digits of a phone number >"); scanf("%d", &q); p = 1; if (q >= 10000) { z = 1; p = 0; printf("Gol durnit! Der Number's too big, Jah see...why not give it another go?\nWith four numbers only this time, too.\n"); } } /* make it into 4 numbers */ v = q; r = (v) / (1000); a = floor(r); w = q; s = ((w) / (100)) - (a * 10); b = floor(s); x = q; t = ((x) / (10)) - ((a * 100) + (b * 10)); c = floor(t); y = q; u = (y) - ((a * 1000) + (b * 100) + (c * 10)); d = floor(u); /* check for special cases such as 1, 9 & 0 */ if ( a == 1 ) { i = 1; } if ( b == 1 ) { j = 1; } if ( c == 1 ) { k = 1; } if ( d == 1 ) { l = 1; } if ( a == 9 ) { i = 4; } if ( b == 9 ) { j = 4; } if ( c == 9 ) { k = 4; } if ( d == 9 ) { l = 4; } if ( a == 0 ) { i = 1; } if ( b == 0 ) { j = 1; } if ( c == 0 ) { k = 1; } if ( d == 0 ) { l = 1; } /* print the number entered */ printf("%d", a ); printf("%d", b ); printf("%d", c ); printf("%d spells:\n", d ); /* begin the combinatorics */ while (e <= i){ while ( f <= j ) { while ( g <= k ) { while ( h <= l ) { /* begin As */ if ( a == 1 ) { printf("1"); } if ( a == 2 ) { if ( e == 1 ) { printf("A"); } if ( e == 2 ) { printf("B"); } if ( e == 3 ) { printf("C"); } } if ( a == 3 ) { if ( e == 1 ) { printf("D"); } if ( e == 2 ) { printf("E"); } if ( e == 3 ) { printf("F"); } } if ( a == 4 ) { if ( e == 1 ) { printf("G"); } if ( e == 2 ) { printf("H"); } if ( e == 3 ) { printf("I"); } } if ( a == 5 ) { if ( e == 1) { printf("J"); } if ( e == 2 ) { printf("K"); } if ( e == 3 ) { printf("L"); } } if ( a == 6 ) { if ( e == 1) { printf("M"); } if ( e == 2 ) { printf("N"); } if ( e == 3 ) { printf("O"); } } if ( a == 7 ) { if ( e == 1) { printf("P"); } if ( e == 2 ) { printf("R"); } if ( e == 3 ) { printf("S"); } } if ( a == 8 ) { if ( e == 1) { printf("T"); } if ( e == 2 ) { printf("U"); } if ( e == 3 ) { printf("V"); } } if ( a == 9 ) { if ( e == 1 ) { printf("W"); } if ( e == 2 ) { printf("X"); } if ( e == 3 ) { printf("Y"); } if ( e == 4 ) { printf("Z"); } } if ( a == 0 ) { printf("0"); } /* end As */ /* start Bs */ if ( b == 1 ) { printf("1"); } if ( b == 2 ) { if ( f == 1 ) { printf("A"); } if ( f == 2 ) { printf("B"); } if ( f == 3 ) { printf("C"); } } if ( b == 3 ) { if ( f == 1 ) { printf("D"); } if ( f == 2 ) { printf("E"); } if ( f == 3 ) { printf("F"); } } if ( b == 4 ) { if ( f == 1 ) { printf("G"); } if ( f == 2 ) { printf("H"); } if ( f == 3 ) { printf("I"); } } if ( b == 5 ) { if ( f == 1) { printf("J"); } if ( f == 2 ) { printf("K"); } if ( f == 3 ) { printf("L"); } } if ( b == 6 ) { if ( f == 1) { printf("M"); } if ( f == 2 ) { printf("N"); } if ( f == 3 ) { printf("O"); } } if ( b == 7 ) { if ( f == 1) { printf("P"); } if ( f == 2 ) { printf("R"); } if ( f == 3 ) { printf("S"); } } if ( b == 8 ) { if ( f == 1) { printf("T"); } if ( f == 2 ) { printf("U"); } if ( f == 3 ) { printf("V"); } } if ( b == 9 ) { if ( f == 1 ) { printf("W"); } if ( f == 2 ) { printf("X"); } if ( f == 3 ) { printf("Y"); } if ( f == 4 ) { printf("Z"); } } if ( b == 0 ) { printf("0"); } /* end Bs */ /* start Cs */ if ( c == 1 ) { printf("1"); } if ( c == 2 ) { if ( g == 1 ) { printf("A"); } if ( g == 2 ) { printf("B"); } if ( g == 3 ) { printf("C"); } } if ( c == 3 ) { if ( g == 1 ) { printf("D"); } if ( g == 2 ) { printf("E"); } if ( g == 3 ) { printf("F"); } } if ( c == 4 ) { if ( g == 1 ) { printf("G"); } if ( g == 2 ) { printf("H"); } if ( g == 3 ) { printf("I"); } } if ( c == 5 ) { if ( g == 1) { printf("J"); } if ( g == 2 ) { printf("K"); } if ( g == 3 ) { printf("L"); } } if ( c == 6 ) { if ( g == 1) { printf("M"); } if ( g == 2 ) { printf("N"); } if ( g == 3 ) { printf("O"); } } if ( c == 7 ) { if ( g == 1) { printf("P"); } if ( g == 2 ) { printf("R"); } if ( g == 3 ) { printf("S"); } } if ( c == 8 ) { if ( g == 1) { printf("T"); } if ( g == 2 ) { printf("U"); } if ( g == 3 ) { printf("V"); } } if ( c == 9 ) { if ( g == 1 ) { printf("W"); } if ( g == 2 ) { printf("X"); } if ( g == 3 ) { printf("Y"); } if ( g == 4 ) { printf("Z"); } } if ( c == 0 ) { printf("0"); } /* end Cs */ /* start Ds */ if ( d == 1 ) { printf("1"); } if ( d == 2 ) { if ( h == 1 ) { printf("A"); } if ( h == 2 ) { printf("B"); } if ( h == 3 ) { printf("C"); } } if ( d == 3 ) { if ( h == 1 ) { printf("D"); } if ( h == 2 ) { printf("E"); } if ( h == 3 ) { printf("F"); } } if ( d == 4 ) { if ( h == 1 ) { printf("G"); } if ( h == 2 ) { printf("H"); } if ( h == 3 ) { printf("I"); } } if ( d == 5 ) { if ( h == 1) { printf("J"); } if ( h == 2 ) { printf("K"); } if ( h == 3 ) { printf("L"); } } if ( d == 6 ) { if ( h == 1) { printf("M"); } if ( h == 2 ) { printf("N"); } if ( h == 3 ) { printf("O"); } } if ( d == 7 ) { if ( h == 1) { printf("P"); } if ( h == 2 ) { printf("R"); } if ( h == 3 ) { printf("S"); } } if ( d == 8 ) { if ( h == 1) { printf("T"); } if ( h == 2 ) { printf("U"); } if ( h == 3 ) { printf("V"); } } if ( d == 9 ) { if ( h == 1 ) { printf("W"); } if ( h == 2 ) { printf("X"); } if ( h == 3 ) { printf("Y"); } if ( h == 4 ) { printf("Z"); } } if ( d == 0 ) { printf("0"); } /* end Ds */ printf(", "); /* put in a space */ n = n + 1; /* more convenient line breaks */ if ( n >= 10 ) { printf("\n"); n = 1; } h = h + 1; } h = 1; g = g + 1; } g = 1; f = f + 1; } f = 1; e = e + 1; } }