Write a loop that displays all possible combinations of two letters where the letters are ‘a’, or ‘b’, or ‘c’, or ‘d’, or ‘e’.

LANGUAGE: C++

CHALLENGE:

Write a loop that displays all possible combinations of two letters where the letters are ‘a’, or ‘b’, or ‘c’, or ‘d’, or ‘e’. The combinations should be displayed in ascending alphabetical order:

aa
ab
ac
ad
ae
ba
bb

ee

SOLUTION:

The Bad News: The content you are trying to access is only available to members.

The Good News: You too can be a member, simply Click Here.

Already a member?

Posted in ,

2 Comments

  1. Alexa on June 20, 2015 at 2:47 pm

    char[] letters = {‘a’, ‘b’, ‘c’, ‘d’, ‘e’};

    for(int i=0; i < 5; i++)

    {

    for(int ii=0; ii < 5 ; ii++)

    {

    System.out.print(letters[i]);

    System.out.println(letters[ii]);

    }

    }

  2. Ben Large on June 30, 2016 at 8:57 pm

    Here is the C version:

    char outerChar;
    char innerChar;

    for (outerChar=’a’; outerChar<='e'; outerChar++){
    for (innerChar='a'; innerChar<='e'; innerChar++){
    printf("%c%c\n",outerChar, innerChar);
    }
    }

Leave a Comment

You must be logged in to post a comment.