Kodewick
Start learning →
Starter←→0 / 50

Unique 3-digit numbers

#021Startera != b && a != c && b != c5 min

Using the digits 1, 2, 3, 4, how many 3-digit numbers can you make where all three digits are different? 123 and 431 are fine, 112 is not. Show each one on its own line, smallest first, then the count on the last line. In the starter, a, b, c are the hundreds, tens and ones, and three loops already try every mix.

Should show
123
124
132
134
142
143
213
214
231
234
241
243
312
314
321
324
341
342
412
413
421
423
431
432
24
main.c
#include <stdio.h>

int main(void) {
    int count = 0;
    for (int a = 1; a <= 4; a++) {
        for (int b = 1; b <= 4; b++) {
            for (int c = 1; c <= 4; c++) {
                // your code here: if all three digits differ, show the number and add 1 to count
            }
        }
    }
    printf("%d\n", count);
    return 0;
}
Ctrl + Enter runs too
Result

Run tries the examples. When they look right, Submit.