By GokiSoft.com| 10:08 05/10/2021|
C Sharp

Hiển thị hình tam giác - Lập trình C# - Loop trong C# BT1398

Thực hiện vẽ hình sau

* * * * * *

* * * * *

* * * *

* * *

* *

*

Độ cao N = 6

Yêu cầu nhập N từ bàn phím. Hiển thị ra hình tương tự trên vs độ cao N

Liên kết rút gọn:

https://gokisoft.com/1398

Bình luận

avatar
Trần Việt Đức Anh [C2010L]
2021-10-01 11:32:44


#Ex1398


using System;

namespace Ex1398
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Enter N:");
            int n = int.Parse(Console.ReadLine());

            int i = n - 1;
            while (i >= 0)
            {
                int j = 0;
                while (j <= i)
                {
                    Console.Write("*");
                    j++;
                }
                Console.WriteLine("");
                i--;
            }
            Console.ReadKey();
        }
    }
}


avatar
Phạm Đăng Khoa [community,C2010L]
2021-09-30 14:03:17



using System;

namespace Lesson01
{
    class Program
    {
        static void Main(string[] args)
        {
            
            int n = 6;

            int i = n - 1;
            while (i >= 0)
            {
                int j = 0;
                while (j <= i)
                {
                    Console.Write("*");
                    j++;
                }
                Console.WriteLine("");
                i--;
            }

        }
    }
}


avatar
Đỗ Minh Tâm [community,C2010G]
2021-09-28 09:22:45



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

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("nhap vao so n:");
            int n = int.Parse(Console.ReadLine());

            int i = n - 1;
            while (i >= 0)
            {
                int j = 0;
                while (j <= i)
                {
                    Console.Write("*");
                    j++;
                }
                Console.WriteLine("");
                i--;
            }

        }
    }
}


avatar
Kim Văn Thiết [community,AAHN-C2009G]
2021-09-23 05:28:19



static void bai1()
        {
            Console.WriteLine("Enter N: ");
            int N = int.Parse(Console.ReadLine());
            int A = N;
            for(int i = 0; i < N; i++)
            {
                int j = 0;
                while ( j < A)
                {
                Console.Write('*');
                    j++;
                }
                A--;
                Console.WriteLine();
               
            }
        }


avatar
Hoàng Văn Huy [community,AAHN-C2009G]
2021-09-23 02:47:34


#Program.cs


using System;

namespace Core
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Enter a number: ");
            int num = Console.Read();
            for(int i = 0; i <= num; i++)
            {
                for(int j = 0; j <= i; j++)
                {
                    Console.Write("*");
                }
                Console.WriteLine();
            }
        }
    }
}


avatar
Hoàng Thiện Thanh [community,AAHN-C2009G]
2021-09-22 02:05:45


#Program.cs


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

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Enter the number of max elements:");
            int n = int.Parse(Console.ReadLine());

            int i = n - 1;
            while (i >= 0)
            {
                int j = 0;
                while (j <= i)
                {
                    Console.Write("*");
                    j++;
                }
                Console.WriteLine("");
                i--;
            }

        }
    }
}


avatar
Nguyễn Việt Hoàng [community,AAHN-C2009G]
2021-09-21 17:27:39

#Program.cs


using System;

namespace Triagle
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Please enter N :");
            int n = int.Parse(Console.ReadLine());
            for(int i = n - 1; i >= 0; i--)
            {
                for (int j = 0; j <= i; j++)
                {
                    Console.Write("*");
                }
                Console.WriteLine("");
            }
            
           
        }

    }
}


avatar
vuong huu phu [T2008A]
2021-05-17 10:36:59



using System;

namespace insao
{
    class Program
    {
        static void Main(string[] args)
        {
            int n;
            Console.WriteLine("Nhap so pan tu");
            n = Int32.Parse(Console.ReadLine());
            for (int i = n; i > 0; i--) {
                for (int j = 0; j < i; j++) {
                    Console.Write(" * ");
                }
                Console.WriteLine();
            }
        }
    }
}


avatar
Nguyễn Anh Vũ [T2008A]
2021-05-17 10:14:02



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

namespace TamGiac
{
    class Program
    {
        static void Main(string[] args)
        {
            for (int i = 6; i >= 1; i--)
            {
                for (int k = i; k >= 1; k--)
                {
                    Console.Write("*");
                }
                Console.WriteLine("\n");
            }
        }
    
}


avatar
Do Trung Duc [T2008A]
2021-05-17 08:33:04



using System;
using System.Collections.Generic;

namespace Inhinhsao
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("NHap N: ");
            int N = Int32.Parse(Console.ReadLine());

            List<string> str = new List<string>(); 
            
            for(int i = 0; i < N; i++)
            {
                str.Add("*");
                foreach(string s in str)
                {
                    Console.Write("{0}", s);
                }

                Console.WriteLine("");
            }
        }
    }
}