Wednesday 19 August 2015

Write a program Star Triangle using C#.Net

program:

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


namespace ConsoleApplication1
{
    class startriangle
    {
        static void Main(string[] args)
        {
           //we provide the value manually 
            int x = 5;
            for (int i = 1; i <= x; i++)
            {
                for (int j = 1; j <= x - i; j++)


                    Console.Write(" ");


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

OUTPUT:

                   *
                 *  *
               *  *   *
             *  *   *   *
           *  *   *   *   *               
        
program 2: 


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


namespace ConsoleApplication1
{
    class startriangle
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Enter the value:");

            //we provide the value Dynamically 
            int x = Convert.ToInt32(Console.ReadLine());
            for (int i = 1; i <= x; i++)
            {
                for (int j = 1; j <= x - i; j++)


                    Console.Write(" ");


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


output:

    Enter the value : 5       

                   *
                 *  *
               *  *   *
             *  *   *   *
           *  *   *   *   *    
        

1 comment:

  1. how to write the code in visual studio and browser in chrome

    ReplyDelete