Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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;
}

>Solution :

You got it mostly right, only the constant values 9 and 8 in the b and c loops are inappropriate, since the triangle’s central axis isn’t always 9; the values are 2*a-1 and 2*a-2, respectively.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading