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

Ikuti Code dibawah ini :

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

namespace part5
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Input the number of an asterisk = ");
            int n = int.Parse(Console.ReadLine());
            int num = 1;
            int mid = (n / 2) + 1;
            Console.WriteLine(mid);
            for (int i = 1; i <= n; i++)
            {
                for (int j = n; j >= i; j--)
                {
                    Console.Write(" ");
                }
                for (int k = 1; k <= i * 2 - 1; k++)
                {
                    Console.Write(num);
                }
                Console.WriteLine();
                if (i < mid)
                {
                    num++;
                }
                else num--;
            }
            Console.ReadLine();
        }
    }
} 

  • Output

Previous
Next Post »