Program to print binary right angle triangle Last Updated : 16 Feb, 2023 Comments Improve Suggest changes Like Article Like Report Binary right angle triangle consists of only 0's and 1's in alternate positions. Examples : Input : 4 Output : 0 1 0 0 1 0 1 0 1 0 Input : 3 Output : 0 1 0 0 1 0 C++ // C program to print binary right angle // triangle. #include <stdio.h> // function to print binary right angle // triangle void binaryRightAngleTriangle(int n) { // declare row and column int row, col; for (row = 0; row < n; row++) { for (col = 0;col <= row; col++) { if (((row + col) % 2) == 0) printf("0"); else printf("1"); printf("\t"); } printf("\n"); } } // driver code int main(void) { // no. of rows to be printed int n = 4; binaryRightAngleTriangle(n); return 0; } Java // Java program to print binary // right angle triangle import java.io.*; public class GFG { // function to print binary right // angle triangle static void binaryRightAngleTriangle(int n) { // declare row and column int row, col; for (row = 0; row < n; row++) { for (col = 0; col <= row; col++) { if (((row + col) % 2) == 0) System.out.print("0"); else System.out.print("1"); System.out.print("\t"); } System.out.print("\n"); } } // Driver code public static void main (String[] args) { // no. of rows to be printed int n = 4; binaryRightAngleTriangle(n); } } // This code is contributed // by Anant Agarwal. Python3 # Python 3 program to print # binary right angle triangle. # function to print binary # right angle triangle def binaryRightAngleTriangle(n): # declare row and column for row in range(0, n): for col in range(0, row + 1): if (((row + col) % 2) == 0) : print("0", end = "") else: print("1", end = "") print("\t", end = "") print("") # Driver Code # no. of rows to be printed n = 4 binaryRightAngleTriangle(n) # This code is contributed # by Smitha C# // C# program to print binary // right angle triangle using System; class GFG { // function to print binary right // angle triangle static void binaryRightAngleTriangle(int n) { // declare row and column int row, col; for (row = 0; row < n; row++) { for (col = 0; col <= row; col++) { if (((row + col) % 2) == 0) Console.Write("0"); else Console.Write("1"); Console.Write("\t"); } Console.WriteLine(); } } // Driver code public static void Main () { // no. of rows to be printed int n = 4; binaryRightAngleTriangle(n); } } // This code is contributed // by vt_m . PHP <?php // PHP program to print binary // right angle triangle. // function to print binary // right angle triangle function binaryRightAngleTriangle($n) { for ($row = 0; $row < $n; $row++) { for ($col = 0;$col <= $row; $col++) { if ((($row + $col) % 2) == 0) printf("0"); else printf("1"); printf("\t"); } printf("\n"); } } // Driver code $n = 4; binaryRightAngleTriangle($n); // This code is contributed by mits ?> JavaScript <script> // JavaScript program to print binary right angle // triangle. // function to print binary right angle // triangle function binaryRightAngleTriangle(n) { // declare row and column var row, col; for (row = 0; row < n; row++) { for (col = 0; col <= row; col++) { if ((row + col) % 2 == 0) document.write("0"); else document.write("1"); document.write(" "); } document.write("<br>"); } } // driver code // no. of rows to be printed var n = 4; binaryRightAngleTriangle(n); // This code is contributed by rdtank. </script> Output0 1 0 0 1 0 1 0 1 0 Time complexity: O(n*n) Auxiliary space: O(1) Comment More infoAdvertise with us Next Article Program to print binary right angle triangle B Bishal Dubey Improve Article Tags : Competitive Programming DSA Basic Coding Problems pattern-printing Practice Tags : pattern-printing Similar Reads Program to print Reverse Floyd's triangle Floydâs triangle is a triangle with first natural numbers. Task is to print reverse of Floydâs triangle.Examples: Input : 4 Output : 10 9 8 7 6 5 4 3 2 1 Input : 5 Output : 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 C++ // CPP program to print reverse of // floyd's triangle #include <bits/stdc++.h> u 3 min read Program to print Sum Triangle for a given array Given a array, write a program to construct a triangle where last row contains elements of given array, every element of second last row contains sum of below two elements and so on. Example: Input: arr[] = {4, 7, 3, 6, 7};Output:8140 4121 19 2211 10 9 134 7 3 6 7 Input: {10, 40, 50}Output:14050 901 9 min read Program to print modified Binary triangle pattern Given an integer N, the task is to print the modified binary tree pattern. In Modified Binary Triangle Pattern, the first and last element of a Nth row are 1 and the middle (N - 2) elements are 0. Examples: Input: N = 6 Output: 1 11 101 1001 10001 100001Input: N = 3 Output: 1 11 101 Approach: From t 5 min read Recursive program to print triangular patterns We have discussed iterative pattern printing in previous post. Examples: Input : 7 Output : * * * * * * * * * * * * * * * * * * * * * * * * * * * * Algorithm:- step 1:- first think for the base condition i.e. number less than 0 step 2:-do the recursive calls till number less than 0 i.e:- printPartte 8 min read Program to print a Hollow Triangle inside a Triangle Given a number N(? 8), the task is to print a Hollow Triangle inside a Triangle pattern.Example: Input: N = 9 Output: * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Approach: Let i be the index for rows and j be the index for columns. Then: For sides of outer triangle: If th 7 min read Like