#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; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter