Star Pattern in C# Console Application

Debendra256
Posted by Co Author(s): Debendra Dash in C# category on for Beginner level | Points: 250 | Views : 765 red flag
Rating: 4.67 out of 5  
 3 vote(s)

We will look into most important star pattern in C# console application, which is asked most of time in interview.

Introduction

This is a simple article where we will look into different star pattern in C# which are frequently asked in  interview.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace variables
{
    class demo
    {


        static void Main(string[] args)
        {
            Console.WriteLine("enter the number");
            int x = Convert.ToInt32(Console.ReadLine());
            for (int i = 1; i <= x; i++)
            {
                Console.WriteLine("");
                for (int j = 1; j <= i; j++)
                {
                    Console.Write(j);
                }
            }
            Console.ReadLine();
        }
    }
}




using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace variables
{
    class demo
    {
        static void Main(string[] args)
        {
            Console.WriteLine("enter the number");
            int x = Convert.ToInt32(Console.ReadLine());
            for (int i = 1; i <= x; i++)
            {
                Console.WriteLine("");
                for (int j = 1; j <= i; j++)
                {
                    Console.Write(i);
                }
            }
            Console.ReadLine();
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace variables
{
    class demo
    {
        static void Main(string[] args)
        {
            Console.WriteLine("enter value of n");
            int n = Convert.ToInt32(Console.ReadLine());
            for (int i = n; i >= 1; i--)
            {
                Console.WriteLine(" ");
                for (int j = 1; j <= i; j++)
                {
                    Console.Write(j);
                }
            }
            Console.ReadLine();
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace variables
{
    class demo
    {
        static void Main(string[] args)
        {
            Console.WriteLine("enter value of n");
            int n = Convert.ToInt32(Console.ReadLine());
            for (int i = n; i >= 1; i--)
            {
                Console.WriteLine(" ");
                for (int j = 1; j <= i; j++)
                {
                    Console.Write("  ");
                }

                for (int q = i; q <= n; q++)
                {
                    Console.Write(" *  ");
                }
            }
            Console.ReadLine();
        }
    }
}




using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Practice
{
    class Program
    {
        static void Main(string[] args)
        {
            for (int i = 6; i >= 1; i--)
            {
                int count = 8;

                for (int x = 1; x <= i; x++)
                {
                    Console.Write(count);
                    count--;
                }
                Console.WriteLine(" ");
            }
            Console.ReadLine();
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Practice
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("enter the value of n");
            int x = Convert.ToInt32(Console.ReadLine());
            for (int i = x; i >= 1; i--)
            {
                Console.WriteLine("");
                for (int j = i; j >= 1; j--)
                {
                    Console.Write(" ");
                }
                for (int s = i; s <= x; s++)
                {
                    Console.Write("* ");
                }
            }
            for (int i = x; i >= 1; i--)
            {
                Console.WriteLine("");
                for (int j = i; j <= x; j++)
                {
                    Console.Write(" ");
                }
                for (int q = i; q >= 1; q--)
                {
                    Console.Write("* ");
                }
            }
            Console.ReadLine();
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;
using System.Data;
using System.IO;

namespace stringoperation
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("enter value of n");
            int x = Convert.ToInt32(Console.ReadLine());
            for (int i = 1; i <= x; i++)
            {
                Console.WriteLine("");
                for (int j = 1; j <= i; j++)
                {
                    Console.Write(j);
                }
                for (int k = x - 1; k >= i; k--)
                {
                    Console.Write("  ");
                }
                for (int l = i; l >= 1; l--)
                {
                    Console.Write(l);
                }
            }
            Console.ReadLine();
        }
    }
}


Conclusion

So these are some of important star pattern asked during interview,Freshers searching for jobs may check this because going for interview.

Page copy protected against web site content infringement by Copyscape

About the Author

Debendra256
Full Name: Debendra Dash
Member Level: Starter
Member Status: Member
Member Since: 10/9/2015 7:13:47 AM
Country: India
Debendra Dash

Nearly 3 years of experiance in various Microsoft Technology.Currently working as a Technical Consultant in R2 international India Pvt Ltd.


About the Co-Author(s)

By Points: 0 | Level: Starter | Status: []

Login to vote for this post.

Comments or Responses

Login to post response

Comment using Facebook(Author doesn't get notification)