Pascal's triangle: Difference between revisions
Content added Content deleted
No edit summary |
No edit summary |
||
Line 219: | Line 219: | ||
last.swap(thisRow); |
last.swap(thisRow); |
||
} |
} |
||
}</lang> |
|||
=={{header|C sharp|C#}}== |
|||
{{trans|Fortran}} |
|||
Produces no output when n is less than or equal to zero. |
|||
<lang csharp>using System; |
|||
namespace RosettaCode { |
|||
class PascalsTriangle { |
|||
public void CreateTriangle(int n) { |
|||
if (n > 0) { |
|||
for (int i = 0; i < n; i++) { |
|||
int c = 1; |
|||
Console.Write(" ".PadLeft(2 * (n - 1 - i))); |
|||
for (int k = 0; k <= i; k++) { |
|||
Console.Write("{0}", c.ToString().PadLeft(3)); |
|||
c = c * (i - k) / (k + 1); |
|||
} |
|||
Console.WriteLine(); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
}</lang> |
}</lang> |
||