[Solved] how do you make a isosceles triangle using for loops?


That should do it:

#include <stdio.h>

#define HEIGHT 5
#define WIDTH 7

int main() {
    int roof = WIDTH / 2;
    int offset = (WIDTH % 2 == 0) ? 1 : 0;

    for(int col_start = roof; col_start > 0; col_start--) {
        if(col_start != roof || offset != 1) {
            
            for(int col = 0; col < col_start; col++) {
                putchar(' ');
            }
            putchar('X');
        

            if(col_start != roof) {
                for(int col = 0; col < (roof - col_start) * 2 - 1 - offset; col++) {
                    putchar(' ');
                }
                putchar('X');
            }
        
            putchar('\n');
        }
    }
    

    for (int rows = 0; rows < HEIGHT; rows++) {
        for (int col = 0; col < WIDTH; col++) {
        if (rows == 0 || rows == HEIGHT - 1) {
            putchar('X');
        } else {

            if (col == 0 || col == WIDTH - 1) {
            putchar('X');
            } else
            putchar(' ');
        }
    }
    putchar('\n');

    }
    return 0;
}

Outputs:

   X
  X X
 X   X
XXXXXXX
X     X
X     X
X     X
XXXXXXX

And with an even width (8):

   XX
  X  X
 X    X
XXXXXXXX
X      X
X      X
X      X
XXXXXXXX

0

solved how do you make a isosceles triangle using for loops?