lundi 10 avril 2023

Alphabet Pattern in C language

i have code C language like this

int main() {
   char A[3][6] = {
      "ABCDE",
      "FGHIJ",
      "KLMNO"
   };

   int i, j, x, y;
   x = 0;
   y = 1;

   for (i=0; i<=2; i++) {
      for (j=0; j<=4; j++) {
         printf("%c ", A[i][j]);
         x++;

         if (x == y) {
            printf("\n");
            y++;
            x=0;
         }
       }
   }
}

If i run the above code, it will display like this :

A 
B C 
D E F 
G H I J 
K L M N O

How can I display pattern the output like below, just by making a few changes to the code above :

        A
      B C
    D E F
  G H I J
K L M N O

O N M L K
  J I H G
    F E D
      C B
        A

Thank you

Aucun commentaire:

Enregistrer un commentaire