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

Ikuti Code dibawah ini :

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

namespace part4
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Input the number of an asterisk = ");
            int n = int.Parse(Console.ReadLine());
            int num=1;
            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();
                num++;
            }
            Console.ReadLine();
        }
    }
} 

  • Output

Previous
Next Post »