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