Q:

Write a program in C# Sharp to print the Floyd's Triangle

0

Write a program in C# Sharp to print the Floyd's Triangle

    1 
    01
    101 
    0101 
    10101

Sample Output:

Print the Floyd's Triangle:                                                                                                         
-----------------------------                       
Input number of rows : 8                                                                                                         
1                                                                                                         
01                                                                                                         
101                                                                                                         
0101                                                                                                         
10101                                                                                                         
010101                                                                                                         
1010101                                                                                                         
01010101

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

using System;  
public class Exercise22  
{  
    public static void Main()
{
    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");
   }
  } 
} 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now