top of page
Writer's pictureThe Tech Platform

10 different Number Pattern Programs in C#




Pattern 1:


class pyramid
{
    public static void Main()
    {
        int num, space;

        while (true)
        {
            Console.Write("Enter a number between 1 to 9 : ");

            num = Convert.ToInt32(Console.ReadLine());

            space = num - 1;

            for (int i = 1; i <= num; i++)
            {
                for (space = 1; space <= (num - i); space++)
                {
                    Console.Write(" ");
                }

                for (int j = 1; j <= i; j++)
                {
                    Console.Write(j);
                }

                for (int k = (i - 1); k >= 1; k--)
                {
                    Console.Write(k);
                }

                Console.WriteLine();

            }
        }

    }
}  


Pattern:2


1 22 333 4444 55555

class NumberPattern
{
    public static void Main()
    {
        int no = 5;

        for (int i = 1; i <= 5; i++)
        {
            for (int j = 1; j <= i; j++)
            {
                Console.Write(i);
            }
            Console.WriteLine();
        }
        Console.ReadKey();  
    }
}


Pattern:3


1 12 123 1234 12345 1234 123 12 1

class Program
    {
 
        public static void Main(string[] args)
        {
            Console.Write("Enter a number: ");
            int n = Convert.ToInt32(Console.ReadLine());
 
            Console.WriteLine();
 
            for(int i = 1; i < n; i++)
            {
                for(int j = 1; j <= i; j++)
                    Console.Write(j.ToString());
                Console.WriteLine();
            }
            for(int i = n; i >= 0; i--)
            {
                for(int j = 1; j <= i; j++)
                    Console.Write(j.ToString());
                Console.WriteLine();
            }
            Console.WriteLine();
        }
    }


Pattern:4


12345 1234 123 12 1

1 12 123 1234 12345

 class Program
    {
 
        public static void Main(string[] args)
        {
            Console.Write("Enter a number: ");
            int n = Convert.ToInt32(Console.ReadLine());
 
            Console.WriteLine();
            for (int i = n; i >= 0; i--)
            {
                for (int j = 1; j <= i; j++)
                    Console.Write(j.ToString());
                Console.WriteLine();
            }
 
            for(int i = 1; i <= n; i++)
            {
                for(int j = 1; j <= i; j++)
                    Console.Write(j.ToString());
                Console.WriteLine();
            }
           
            Console.WriteLine();
        }
    }


5. Pattern:5


1 01 101 0101 10101

class Program
{

    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");

        }
    }
}


Pattern: 6


1 2 3 4 5 6 7 8 9 10

public static void Main(string[] args)
    {
        int i, j, rows, k = 1;

        Console.Write("\n\n");
        Console.Write("Display the pattern like right angle triangle with number increased by 1:\n");
        Console.Write("---------------------------------------------------------------------------");
        Console.Write("\n\n");

        Console.Write("Input number of rows : ");
        rows = Convert.ToInt32(Console.ReadLine());
        for (i = 1; i <= rows; i++)
        {
            for (j = 1; j <= i; j++)
                Console.Write("{0} ", k++);
            Console.Write("\n");
        }  
    }


Pattern:7


1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 1 2 3 4 1 2 3 1 2 1

class Program
{

    public static void Main(string[] args)
    {
        for (int i = 1; i <= 5; i++)
        {
            for (int j = 1; j <= i; j++)
            {
                Console.Write("" + (j));

            }
            Console.WriteLine("");

        }

        for (int k = 4; k >= 0; --k)
        {

            for (int j = 1; j <= k; j++)
            {
                Console.Write("" + (k));

            }
            Console.WriteLine("");
        }
    }
}


Pattern:8

 public static void Main(string[] args)
    {
        int row, i, j, k;
        Console.Write("Enter the no. of row you want to print: ");
        row = Convert.ToInt32(Console.ReadLine());

        for (i = 0; i <= row; i++)
        {
            k = 1;
            for (j = i; j <= row - 1; j++)
                Console.Write(" ");

            for (j = 0; j <= i; j++)
            {
                Console.Write("{0} ", k);
                k = (k * (i - j) / (j + 1));
            }
            Console.WriteLine();
        }
        Console.ReadLine();  
    }


Pattern 9:


5 54 543 5432 54321

 public static void Main(string[] args)
    {
        {
            int i = 5;
            while (i >= 1)
            {
                int j = 5;
                while (j >= i)
                {
                    Console.Write(j);
                    j--;
                }
                i--;
                Console.WriteLine();
            }
            Console.Read();
        }
    }


Pattern:10

 public static void Main(string[] args)
    {
        int i, j, k;

        for (i = 1; i <= 7; i++)
        {
            for (j = 1; j <= i; ++j)
                Console.Write(j);

            for (k = 7 - i; k >= 1; k--)
                Console.Write("*");

            Console.Write("\n");
        }

        Console.ReadLine();

    }

Read more:


Source: Csharpstar


The Tech Platform

0 comments

Comments


bottom of page