213k views
3 votes
Given an char variable last that has been initialized to a lowercase letter, write a loop that displays all possible combinations of two letters in the range 'a' through last. The combinations should be displayed in ascending alphabetical order: For example, if last was initialized to 'c' the output should be aa

User MOHRE
by
4.8k points

1 Answer

1 vote

Answer:

for (char i='a'; i<='e'; i++){

for (char j='a'; j<='e'; j++){

cout << i<< j<< "\\";

}

}

Step-by-step explanation:

The loop runs all characters from the inner while the outer holds one character, by doing so, a will be matched with a,b,c,... Like wise b,c,d,... and on it goes.

User Zelite
by
5.1k points