Welcome to Dream.In.Code
Become a C# Expert!

Join 150,393 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,037 people online right now. Registration is fast and FREE... Join Now!




C#

 
Reply to this topicStart new topic

C#, printing pyramid using C#

kaviraj_01
10 Mar, 2008 - 08:18 PM
Post #1

New D.I.C Head
*

Joined: 24 Feb, 2008
Posts: 5

Hi,
Good morning this is raj here. i wana print a pyramid by using C#.i have used array it is not giving requireed answer wub.gif


Attached File(s)
Attached File  1.txt ( 710bytes ) Number of downloads: 43
User is offlineProfile CardPM
+Quote Post

Nykc
RE: C#
10 Mar, 2008 - 09:00 PM
Post #2

That Just Happened!
Group Icon

Joined: 14 Sep, 2007
Posts: 4,509



Thanked: 18 times
Dream Kudos: 275
My Contributions
code.gif

So we can have a look at what is going on.

smile.gif - This should be in the C# forum.

This post has been edited by Nykc: 10 Mar, 2008 - 09:01 PM
User is online!Profile CardPM
+Quote Post

KYA
RE: C#
10 Mar, 2008 - 09:47 PM
Post #3

#include <nerd.h>
Group Icon

Joined: 14 Sep, 2007
Posts: 5,953



Thanked: 159 times
Dream Kudos: 1375
My Contributions
++ and # don't look anywhere near the same...
User is online!Profile CardPM
+Quote Post

davegeek
RE: C#
12 Mar, 2008 - 05:37 AM
Post #4

D.I.C Head
Group Icon

Joined: 30 Jan, 2008
Posts: 81



Thanked: 2 times
My Contributions
Try these code snippets:

CODE

using System;
namespace DisplayXWithNestedLoops
{
    public class Program
    {
        public static void Main(string[] args)
        {
            int nConsoleWidth = 40;
            // iterate through the rows of the ôboxö
            for (int nRowNum = 0; nRowNum < nConsoleWidth; nRowNum += 2)
            {
                // now iterate through the columns
                for (int nColumnNum = 0; nColumnNum < nConsoleWidth; nColumnNum++)
                {
                    // the default character is a space
                    char c = ' ';
                    // if the column number and row number are the same . . .
                    if (nColumnNum == nRowNum)
                    {
                        // . . .replace the space with a backslash
                        c = '\\';
                    }
                    // if the column is on the opposite side of the row . . .
                    int nMirrorColumn = nConsoleWidth - nRowNum;
                    if (nColumnNum == nMirrorColumn)
                    {
                        // . . .replace the space with a slash
                        c = '/';
                    }
                    // output whatever character at the current
                    // row and column
                    Console.Write(c);
                }
                Console.WriteLine();
            }
            // wait for user to acknowledge the results
            Console.WriteLine("Press Enter to terminate...");
            Console.Read();
        }
    }
}



Also:
CODE

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

namespace ConsoleApplication5
{
    class Program
    {
        static void Main(string[] args)
        {
            int dim = 20;

            for (int i = 0; i < dim; i += 2)
            {
                for (int j = 0; j < dim; j++)
                {
                    char c = ' ';
                    if (i == j)
                    { c = '\\'; }
                    //int n = dim - i;
                    if (j == dim - i)
                    { c = '/'; }
                    Console.Write(c);
                }
                Console.WriteLine();


            }
        }
    }
}


They are printing the X sign, u have got to figure out how to print the pyramid.

This post has been edited by davegeek: 12 Mar, 2008 - 05:38 AM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 05:59PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month