CGC_Codes

Print Binary Triangle

Jun 5th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.98 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6.  
  7.  
  8. namespace Program
  9.  
  10. {
  11.  
  12.     class Program
  13.  
  14.     {
  15.  
  16.         public static void Main(String[] args)
  17.  
  18.         {
  19.  
  20.             int p, lastInt = 0, input;
  21.  
  22.             Console.WriteLine("Enter the Number of Rows : ");
  23.  
  24.             input = int.Parse(Console.ReadLine());
  25.  
  26.             for (int i = 1; i <= input; i++)
  27.  
  28.             {
  29.  
  30.                 for (p = 1; p <= i; p++)
  31.  
  32.                 {
  33.  
  34.                     if (lastInt == 1)
  35.  
  36.                     {
  37.  
  38.                         Console.Write("0");
  39.  
  40.                         lastInt = 0;
  41.  
  42.                     }
  43.  
  44.                     else if (lastInt == 0)
  45.  
  46.                     {
  47.  
  48.                         Console.Write("1");
  49.  
  50.                         lastInt = 1;
  51.  
  52.                     }
  53.  
  54.                 }
  55.                 Console.Write("\n");
  56.  
  57.             }
  58.  
  59.             Console.ReadLine();
  60.  
  61.         }
  62.  
  63.     }
  64.  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment