Password combinations

hiiiiz

i have a question... how can i write a program that generates all possible combinations for a number of letters.

like if i had 4 digits... the number of possible combinations = 26^4 right?? but how can i display them all ??

1
2
3
4
5
6
7
8
9
10
11
12
char c[5];
c[4] = '\0'; // Important

for (c[0] = 'a'; c[0] <= 'z'; c[0]++) {
    for (c[1] = 'a'; c[1] <= 'z'; c[1]++) {
        for (c[2] = 'a'; c[2] <= 'z'; c[2]++) {
            for (c[3] = 'a'; c[3] <= 'z'; c[3]++) {
                cout << c << endl;
            }
        }
    }
}
You cannot generalize that. It depends on the underlying alphabet. If that alphabet has n elements and your password four digits, there are n^4 possible combinations. With the Roman alphabet, you still have to decide whether to distinguish between lower-case and upper-case characters.
Topic archived. No new replies allowed.