## 3 replies

Last post Nov 10, 2012 10:59 PM by ToughMan

• Vipindas

Contributor

4392 Points

933 Posts

### logical question

Try this

```static void Main(string[] args)
{
int binom = 1, q = 0, r, x;

//Input from the user12.
Console.WriteLine("Enter the number of rows");
int p = Int32.Parse(s);

Console.WriteLine("The Pascal Triangle");
while (q < p)
{
for (r = 40 - (3 * q); r > 0; --r)
Console.Write(" ");
for (x = 0; x <= q; ++x)
{
if ((x == 0) || (q == 0))
binom = 1;
else
binom = (binom * (q - x + 1)) / x;
Console.Write(binom);
}
Console.Write("\n ");
++q;
}
}```

Hope this helps...

• gerrylowry

Star

14297 Points

5797 Posts

### Re: logical question

interesting subject:  "logical question".

for me, as a former community college computer science instructor, i am the suspicious type ... this looks much more like a better subject might be "will you do my homework for me?"; for that reason, i'm compelled to ask you, is this a homework assignment?

#### moorthi ks

i need program for above output

i need food to live.

especially in winter, because i live in Canada, i need shelter to avoid dying from hypothermia.

moorthi ks, perhaps you will share with your peers here at forums.asp.net why you need to programmatically produce this:

```1
1 2 1
1 3 3 1
1 4 6 4 1```

MORE  INFORMATION

(a) a better subject might be "How can i produce Pascal's Triangle in c#?"

http://en.wikipedia.org/wiki/Pascal's_triangle

(b) the solution by Vipindas has some flaws:

(1) in my favourite tool for experimenting with c#, this line crashes:

InvalidOperationException
Cannot read keys when either application does not have a console or when console input has been redirected from a file. Try Console.Read.

(2) the output does not align in a pretty way:

```Enter the number of rows
The Pascal Triangle
1
11
121
1331```

moorthi ks, can you fix this?

(3) the program does not object to a request for zero rows or minus one rows.

(4) the program begins to output negative values if you ask for 31 or more rows.

(5) moorthi ks, if this is a homework question, you may hope that your instructor does not do this:

http://lmgtfy.com/?q=Input+from+the+user12+Console.WriteLine(%22The+Pascal+Triangle%22)%3B

g.

B-)  Gerry Lowry, Chief Training Architect, Paradigm Mentors Learning never ends... +1 705-999-9195 wasaga beach, ontario canada TIMTOWTDI =.there is more than one way to do it
• Paul Linton

Star

9555 Points

2784 Posts

### Re: logical question

Nov 10, 2012 07:31 PM|Paul Linton|LINK

`Console.WriteLine("     1    \r  1 2 1  \r 1 3 3 1 \r1 4 6 4 1");`

Got a c# problem? Try .NET Book Zero from Charles Petzold, it's a free pdf.
• ToughMan

Member

740 Points

545 Posts