Question: Program to print the binary Right triangle.
11 0
1 0 1
1 0 1 0
1 0 1 0 1
Code Snippet:
- using System;
- public class Pattern
- {
- public static void Main()
- {
- int row, col, n;
- Console.Write("Enter the no. of row: ");
- n = Convert.ToInt32(Console.ReadLine());
- for(row = 1; row <= n; row++)
- {
- for(col = 1; col <= row; col++)
- {
- if(col%2 == 0)
- Console.Write("0 ");
- else
- Console.Write("1 ");
- }
- Console.WriteLine();
- }
- Console.ReadLine();
- }
- }
Fig: Screenshot of Output |