• Top Posts

    How to write a program to print triangle in the shape of Floyd's


    • By using this program we can print the Floyd's triangle.
    • Its length depends on what ever the number entered by us.
    • Result in the for of  0's and 1's 




     public static void Main(string[] args)  
         {  
           int i, j, n, p, q;  
           Console.Write("\n\n");  
           Console.Write("Print the Floyd's Triangle:\n");  
           Console.Write("-----------------------------");  
           Console.Write("\n\n");  
           Console.Write("Input number of rows : ");  
           n = Convert.ToInt32(Console.ReadLine());  
           for (i = 1; i <= n; i++)  
           {  
             if (i % 2 == 0)  
             { p = 1; q = 0; }  
             else  
             { p = 0; q = 1; }  
             for (j = 1; j <= i; j++)  
               if (j % 2 == 0)  
                 Console.Write("{0}", p);  
               else  
                 Console.Write("{0}", q);  
             Console.Write("\n");  
             Console.ReadLine();  
           }  
         }  
    

    No comments

    Post Top Ad

    ad728

    Post Bottom Ad

    ad728