Draw inverted Triangle

PHOTO EMBED

Sun Jun 09 2024 11:36:42 GMT+0000 (Coordinated Universal Time)

Saved by @meanaspotato #c

#include <stdio.h>

void draw_inverted_triangle(int height) {
    for (int i = 0; i < height; ++i) {
        // Print leading spaces
        for (int j = 0; j < i; ++j) {
            putchar(' ');
        }

        // Print backslash
        putchar('\\');

        // Print inner spaces
        for (int j = 0; j < 2 * (height - i - 1); ++j) {
            putchar(' ');
        }

        // Print forward slash
        putchar('/');

        // Move to the next line
        putchar('\n');
    }
}

int main() {
    int height;

    // Get the height from the user
    printf("enter height: \n");
    scanf("%d", &height);

    // Print the top line of underscores
    for (int i = 0; i < 2 * height; ++i) {
        putchar('_');
    }
    putchar('\n');

    // Draw the inverted triangle
    draw_inverted_triangle(height);

    return 0;
}
content_copyCOPY