Cara membuat program sederhana print asterisk(bintang) c# Asp.Net Part9

Ikuti Code dibawah ini :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace part9
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Input the number of an asterisk = ");
            int nfinal = int.Parse(Console.ReadLine());
            int nmid = (((nfinal - 1) / 2) + 1);
            for (int i = 1; i <= nfinal; i++)
            {
                for (int j = 1; j <= nfinal; j++)
                {
                    if (i == j || j == nfinal + 1 - i)
                    {
                        Console.Write("[*]");
                    }
                    else
                    {
                        int corx = nfinal; int cory = 1;
                        int a = nfinal;
                        for (int k = 1; k <= nmid; k++)
                        {

                            if (i == corx || i == cory || j == corx || j == cory)
                            {
                                Console.Write("[{0}]", a);
                                break;
                            }
                            corx--; cory++; a = a - 2;
                        }
                    }
                }
                Console.WriteLine(" ");
            }
            Console.ReadLine();
        }
    }
}

  • Output

Previous
Next Post »