119k views
2 votes
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

in c programming

User Shawntell
by
5.2k points

1 Answer

4 votes

Answer:

The program to this question can be given as:

Program:

#include <stdio.h> //include header file.

int main() //defining main method

{

char i,j; //defining variable

for (i='a'; i<='e'; i++) //outer loop for column

{

for (j='a'; j<='e'; j++) //inner loop for row

{

printf("%c%c\\",i,j); //print value

}

}

return 0;

}

Output:

image.

Step-by-step explanation:

  • In the above C language program, firstly a header file is included. Then the main method is defined in this, a method contains a char variable that is "i and j". This variable is used in for loop, that is used to print the pattern.
  • To print the following patter two for loop is used the outer loop is used for print columns and the inner loop prints row.
  • In C language to print character, we use "%c" inside a loop print function is used, that prints characters.
Write a loop that displays all possible combinations of two letters where the letters-example-1
User DirtyMind
by
5.7k points