Wednesday, 23 April 2014

C# program to print pyramid structure.

a)          1
              2  3
              4  5  6
              7  8  9  10


Source code:

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

namespace pyramid1
{
    class pyramidd
    {
        public void pyramid1()
        {

            int n;
            int i, c;
            int a=1;

            Console.Write("Enter the number of rows of Floyd's triangle to print\n");
            n = int.Parse(Console.ReadLine());

            for (i = 1; i <= n; i++)
            {
                for (c = 1; c <= i; c++)
                {
                    Console.Write(" "+a);
                    a++;
                }
                Console.Write("\n");
            }

           
            Console.Read();
               
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            pyramidd p = new pyramidd();
            p.pyramid1();

        }
    }

}

No comments:
Write comments

Featured post

List of Universities in Karnataka offering M.Sc Computer Science

The post-graduate programme in Computer Science (M.Sc Computer Science) contains two academic years duration and having a four semesters....

Popular Posts

Copyright @ 2011-2016