Tuesday, June 19, 2012

printing 1 12 123 1234 12345 in triangle in c#


using System;


namespace counting
{
    class Program
    {
        static void Main(string[] args)
        {
            int i, j;
            for (i = 1; i <= 5; i++)
             
            {
                for (j =1; j <= i; j++)
                {
                    Console.Write(""+(j));

                }
                Console.WriteLine("");

            }
            Console.ReadKey();
        }
    }
}

Output:
1
12
123
1234
12345




//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;
            for (i = 1; i <=n; i++)
         
            {
                for (j = 1; j <= i; j++)
                {
                   
                    Console.Write(""+j);
                }
                Console.WriteLine("");
            }
            Console.ReadKey();
        }
    }
}

Output:


Enter no for range
6
1
12
123
1234
12345
123456



8 comments:

  1. if i want to add range?? then?

    ReplyDelete
  2. Code:

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

    namespace Basic_Practicals
    {
    class Program
    { //Printing 1 12 123 in triangle
    static void Main(string[] args)
    {
    int i, j,n = 0;
    Console.Write("Enter No for the range :");
    n = int.Parse(Console.ReadLine()); // Get number of Line from User
    Console.WriteLine("");
    for (i = 1; i < n; i++) // Loop to go on next line
    {
    for (j = 1; j <= i; j++) // Loop to print number
    {
    Console.Write("" + j);
    }
    Console.WriteLine("");
    }
    Console.ReadLine();
    }
    }
    }

    Output:
    Enter No for the range :4

    1
    12
    123

    ReplyDelete
  3. #include
    #include
    void main()
    {
    int j,k;
    clrscr();
    for(j=1;j=4;j++)
    {
    for(k=1;k<=j;k++)
    {
    printf("%d",j);
    }
    printf("\n");
    }
    getch();
    }

    ReplyDelete
  4. 0
    101
    21012
    3210123
    432101234
    54321012345
    For this I want program.

    ReplyDelete