Sponsored Ad

Saturday, March 12, 2011

How to write C# Program to Print Star Triangle

This program will help beginners to write their lab assignment. You can take the logic from below given code. There is 3 loops

First loop is for printing limit and second loop is for space , third loop is for  printing star.

image

C# Program to print star triangle:

using System;

namespace MyApp
{
    class triangle_class
    {
        static void Main(string[] args)
        {
            int number = 12;

            for (int i = 1; i <= number; i++)
            {
                for (int j = 1; j <= number - i; j++)
                    Console.Write(" ");
                for (int k = 1; k <= i; k++)
                    Console.Write(" *");
                Console.WriteLine("");
            }                      
            Console.ReadLine();
        }
    }
}

2 comments:

  1. using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Threading;

    namespace Pyramid
    {
    class Program
    {
    static void Main(string[] args)
    {
    int n = 5;
    for (int i = 1; i <= n; i++)
    {
    for (int j = 1; j <= n - i; j++)
    {
    Console.Write(" ");
    }
    for (int k = 1; k <= 2 * i - 1; k++)
    {
    Console.ForegroundColor = ConsoleColor.Red;
    Console.Write("* ");
    Thread.Sleep(50);
    }
    Console.WriteLine();
    }

    }
    }
    }

    ReplyDelete
  2. *
    * * *
    * * * * *
    * *
    * * * *
    * * * * * *
    * * * *
    * *
    * * * * *
    * * *
    *

    ReplyDelete

Sponsored Ad

Development Updates