Wednesday 23 April 2014

C# program to print pyramid structure 2

b)                 1
                         2   3    4
                    5   6   7    8   9


Source code:
  
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace pyramid1
{
    class pyramidd
    {
        public void pyramid1()
        {
            int no;
            int rw;
            int c;
            int spc;

            Console.WriteLine("Enter number of rows : ");
            no= int.Parse(Console.ReadLine());
           

            for (rw = 1; rw <= no; rw++)
            {
                for (spc = no; spc >= rw; spc--)
                {
                    Console.Write(" ");
                }
                for (c = 1; c <= rw; c++)
                {
                    Console.Write(" " +c);
                }
                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-2022