My First Blog Post



This is my first blog post as a blogger, originally located at felatuns.blogspot.com. It was an assignment that was given to my class when we were in the third year in the university. It is a C++ console program that is to display a pyramid on the console window.
The pyramid height is to be supplied as well as the character used in building the pyramid.
I have equally ported the C++ program to C#

 C++

 # include
 # include
 void main()
 {
     int height;
     char design;
     cout<"enter pyramid height";
     cin>>height;
     cout<<"enter pyramid design";
     cin>>design>>endl;
     for (int i = 0; i < height; i++)
     {
        for (int k = i; k < height; k++)
        {
            cout<<" ";
        }
        for (int j = 2 * i + 1; j > 0; j--)
        {
            cout<< design
        }
        cout<<""<< endl
     }
     getch();
 }


C#

 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 namespace Pyramid
 {
        class Program
         {
            static void Main(string[] args)
            {
                int height;
                char design;
                Console.Write("enter pyramid height ");
                height = int.Parse(Console.ReadLine());
                Console.WriteLine("");
                Console.WriteLine("");
                Console.Write("enter pyramid design ");
                design = char.Parse(Console.ReadLine());
                Console.WriteLine("");
                Console.WriteLine("");
                for (int i = 0; i < height; i++)
                {
                    for (int k = i; k < height; k++)
                    {
                        Console.Write(" ");
                     }
                    for (int j = 2 * i + 1; j > 0; j--)
                    {
                        Console.Write(design);
                    }
                Console.WriteLine("");
                }
                Console.ReadLine();
             }
         }
 }
        

This is the program output after having supplied 30 as the pyramid height and 8 as the
pyramid design.






Share this page on


  0 People Like(s) This Page   Permalink  

 Click  To Like This Page

comments powered by Disqus

page