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.
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();
}
}
}
using System;
ReplyDeleteusing 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* * *
* * * * *
* *
* * * *
* * * * * *
* * * *
* *
* * * * *
* * *
*