mercredi 12 avril 2023

C program for a reverse triangle pattern

I want to draw a pattern like this:

enter image description here

the code below is what I tried and the output for this code is like this:

enter image description here

#include <stdio.h>

int main() {
  int a, b, c, s;
  for (a = 5; a >= 1; a--) {
    for (s = a; s <= 4; s++) {
      printf(" ");
    }
    for (b = a; b <= 9; b++) {
      printf("%d", b);
    }
    for (c = 8; c >= a; c--) {
      printf("%d", c);
    }
    printf("\n");
  }
  return 0;
}

Aucun commentaire:

Enregistrer un commentaire