Program to print a Hollow Triangle inside a Triangle | C ++ implementation of the above approach ; Function to print the pattern ; Loop for rows ; Loop for column ; For printing equal sides of outer triangle ; For printing equal sides of inner triangle ; For printing base of both triangle ; For spacing between the triangle ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void printPattern ( int n ) { int i , j ; for ( i = 1 ; i <= n ; i ++ ) { for ( j = 1 ; j < 2 * n ; j ++ ) { if ( j == ( n - i + 1 ) || j == ( n + i - 1 ) ) { cout << " * ▁ " ; } else if ( ( i >= 4 && i <= n - 4 ) && ( j == n - i + 4 j == n + i - 4 ) ) { cout << " * ▁ " ; } else if ( i == n || ( i == n - 4 && j >= n - ( n - 2 * 4 ) && j <= n + n - 2 * 4 ) ) { cout << " * ▁ " ; } else { cout << " ▁ " << " ▁ " ; } } cout << " STRNEWLINE " ; } } int main ( ) { int N = 9 ; printPattern ( N ) ; }