#Day 17 :101 Days Pyramid Pattern in C# .NET

 

#Day 17: Creating a Binary Pyramid Pattern Starting with 0 in C#

Welcome to Day 17 of our C# programming patterns series. 

In today's post, we'll create a binary pyramid pattern that starts with 0. 

This pattern alternates between 0s and 1s in a pyramid shape, providing an excellent way to practice using nested loops and modulus operations in C#. 

Let’s explore the code to bring this pattern to life.

Here’s the pattern:

0
1 0
0 1 0
1 0 1 0
0 1 0 1 0

Here's the code:

To achieve this, we'll use nested loops to control the rows and columns of the pyramid. Here’s the complete code:


Source Code :

using System;
namespace Pyramid
{
    internal class Program
    {
        static void Main(string[] args)
        {
            int n = 5;
       
            for(int i = 1; i <= n; i++)
            {
                for(int j=i;j>=1;j--)
                {
                    if (j % 2 == 0)
                    {
                        Console.Write(1);
                    }
                    else
                    {
                        Console.Write(0);
                    }                    
                }
                Console.WriteLine();
            }
            Console.Read();
        }
    }
}

OutPut:


Stay tuned for Day 18, where we'll continue exploring more C# patterns and concepts!

Dont forget to share this post if you found it helpful and follow us for more C# programming tips and tutorials. Happy coding!

Related Posts:

#Day 1:Number Pyramid in C#



#Day 5:Alphabet Pyramid Pattern

#Day 6:Creating an Alphabet Triangle Pattern in C#

#Day 7:Creating an Reverse Alphabet Triangle Pattern in C#

#Day 8: Creating an Inverted Alphabet Triangle Pattern in C#

#Day 9: Creating a Numeric Triangle Pattern in C#

#Day 10: Creating a Reverse Numeric Triangle Pattern in C#.Net. 


 Pattern Follow us on Instagram: 

@LearnCodingWithDotNet for daily coding patterns and tips.



No comments:

Post a Comment