Tuesday, June 19, 2012

printing 1 23 456 in triangle in c#


using System;


namespace count_increment
{
    class Program
    {
        static void Main(string[] args)
        {
            int i, j, count = 0;
            for (i = 0; i <3; i++)
         
            {
                for (j = 0; j <= i; j++)
                {
                    count++;
                    Console.Write(""+count);
                }
                Console.WriteLine("");
            }
            Console.ReadKey();
        }
    }
}


Output
1
23
456



//giving range

using System;


namespace count_increment
{
    class Program
    {
        static void Main(string[] args)
        {
            int n;
            Console.WriteLine("Enter no for range");
            n = int.Parse(Console.ReadLine());
            int i, j, count = 0;
            for (i = 1; i <=n; i++)
           
            {
                for (j = 1; j <= i; j++)
                {
                    count++;
                    Console.Write(""+count);
                }
                Console.WriteLine("");
            }
            Console.ReadKey();
        }
    }
}

Output

Enter no for range
5
1
23
456
78910
1112131415

6 comments:

  1. Very good post.. Some of the most useful pgms.. thanks alot...

    ReplyDelete
  2. its very simple and easy to understand. thank alot...

    ReplyDelete
  3. Replies
    1. please explain javascript programe

      Delete
    2. I want
      7 8 9 10
      4 5 6
      2 3
      1 this order in c# program

      Delete