C# Program:To print stars in a traingle shape

Monday, 13 February 2012
using System;
class Test
{
    public static void Main()
    {
        for (int i = 1; i <= 5; i++)
        {
            for (int j = 1; j <=5 - i; j++)
            {
                Console.Write(" ");
            }
                for (int k = 1; k <= i; k++)
                {
                    Console.Write(" *");
                }
        Console.WriteLine("");
        }
    }
}

6 comments:

  1. Unknown said...:

    nice work: for more code visit:
    http://webtutorials55.blogspot.com/

  1. Unknown said...:

    class Class1
    {

    static void Main(string[] args)
    {
    Console.WriteLine("Enter the number of rown you wanna print into the pyramid");
    int x=Convert.ToInt32(Console.ReadLine());
    for(int i=1;i<=x;i++)
    {
    for(int j=x;j>=1;j--)
    {
    if(j<=i)
    {
    Console.Write(" *");
    }
    else
    Console.Write(" ");
    }
    Console.WriteLine();
    }
    Console.ReadLine();
    }

    }

  1. Unknown said...:

    odd and even number in triangle shape ..... please give me code for this output
    2
    3 5
    2 4 6
    3 5 7 9

  1. Unknown said...:
    This comment has been removed by the author.
  1. Unknown said...:

    class Program
    {
    static void Main(string[] args)
    {
    Console.Write("Enter the number of rown you wanna print into the pyramid:");
    int x = Convert.ToInt32(Console.ReadLine());
    int temp = 0;
    int temp1 = 0;
    for (int i = 2; i <= x; i++)
    {
    temp = 0;
    temp1 = 0;
    for (int j = 2; j <= i; j++)
    {
    //check odd number
    if (i % 2 != 0)
    {
    temp = temp + 1;
    Console.Write((j + temp) + " ");
    }
    else
    {

    Console.Write((j + temp1) + " ");
    temp1++;
    }
    }
    Console.WriteLine();
    }
    Console.ReadLine();
    }
    }

  1. Unknown said...:

    How to print prime number in pyrimid shape
    1
    2 3
    5 7 11

Post a Comment