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

Respuesta :

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\n",i,j); //print value

}

}

return 0;

}

Output:

image.

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.
Ver imagen codiepienagoya
ACCESS MORE
EDU ACCESS
Universidad de Mexico