Search This Blog

Sunday, 13 September 2015

Square design program in C#

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

namespace ConsoleApplication7
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Enter the number: ");
            int num = Convert.ToInt32(Console.ReadLine());
            for (int j = 1; j <= num; j++)
            {
                Console.Write("*");
            }

            for (int l = 1; l <= num - 2; l++)
            {
                Console.WriteLine("");
                for (int m = 1; m <= 1; m++)
                {
                    Console.Write("*");
                }
                for (int o = 1; o <= num - 2; o++)
                {
                    Console.Write(" ");
                }
                for (int p = 1; p <= 1; p++)
                {
                    Console.Write("*");
                }
            }
            Console.WriteLine("");
            for (int q = 1; q <= num; q++)
            {
                Console.Write("*");
            }
            Console.WriteLine("");
            Console.ReadKey();
        }
    }
}

Output:

Enter the number: 5

*****
*   *
*   *
*   *
*****

No comments:

Post a Comment